B. Interesting drink

链接

[http://codeforces.com/group/1EzrFFyOc0/contest/706/problem/B]

题意

给你n个数,q次查询,每次输入一个m,问n个数中有多少个数小于等于m

思路

先排序,再用upper_bound找,该函数返回第一个大于m的下标。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("in.txt","r",stdin);
	int n,a[100005];
	int q,i,m;
	while(cin>>n){
		memset(a,0,sizeof(a));
		for(i=0;i<n;i++)
		cin>>a[i];
		sort(a,a+n);
		cin>>q;
		for(i=0;i<q;i++)
		{
			cin>>m;
			int ans = upper_bound(a, a+n, m) - a;
			printf("%d\n", ans);
		}
	}
	return 0;
}
posted @ 2018-08-08 16:19  ChunhaoMo  阅读(177)  评论(0)    收藏  举报