题意:给2个数组(无序的)啊a,b,判断b数组中的每一个元素大于a数组中个数。
ACcode:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
vector<int> v;
int main()
{
int x, n, m;
scanf("%d%d",&n,&m);
for(int i=0; i<n; i++)
{
scanf("%d",&x);
v.push_back(x);
}
sort(v.begin(),v.end());
for(int i=0; i<m; i++)
{
scanf("%d", &x);
int pos = lower_bound(v.begin(),v.end(), x+1)- v.begin();
printf("%d ",pos);
}
printf("\n");
return 0;
}
lower_bound的详细: 参考链接
vector的详细:参考链接
Educational Codeforces Round 2 B. Queries about less or equal elements
原文:http://www.cnblogs.com/lzeffort/p/5059026.html