【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;
}
上一篇:Android 项目总结(View控件之ActionBarDrawerToggle)


下一篇:POJ2505 A multiplication game[博弈论]