【TYVJ 1463】智商问题 (闲得无聊)

老老实实写二分。

#include<cstdio>
#include<algorithm>
using namespace std;
int n, a[1000001], x;
int main()
{
	scanf("%d", &n);
	for(int i=1; i<=n; ++i)
	   scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
	while(scanf("%d",&x)!=EOF) {
		if (x > a[n]) {printf("%d\n", n + 1); continue;}
		int left = 1, right = n, mid;
		while (left < right) {
			mid = (left + right) >> 1;
			if (x <= a[mid])
				right = mid;
			else
				left = mid + 1;
		}
		printf("%d\n", left);
	}
	return 0;
}

 

posted @ 2016-03-30 19:44  abclzr  阅读(122)  评论(0编辑  收藏  举报