1、CF 706B Interesting drink
2、链接:http://codeforces.com/problemset/problem/706/B
3、总结:二分
题意:给出n个数,再给出q个mi,每次求n个数里有多少个数<=mi
#include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio> using namespace std; #define LL long long #define INF 0x3f3f3f3f const int N=100100; int x[N]; int main() { int n,q,m; while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) scanf("%d",&x[i]); sort(x+1,x+n+1); scanf("%d",&q); for(int i=0;i<q;i++) { scanf("%d",&m); int l=1,r=n,mid; while(l<=r){ mid=(l+r)/2; if(m<x[mid]){ r=mid-1; }else if(m>=x[mid]){ l=mid+1; } } cout<<r<<endl; } } return 0; }