[CF]600B - Queries about less or equal elements
題目:
http://codeforces.com/problemset/problem/600/B
----------------------------------------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200010
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int a[MAXN] = {0},i=0,c = 0,*sum,b[MAXN] = {0};
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
for(int i=0;i<m;i++)
scanf("%d",&b[i]);
for(int i=0;i<m;i++)
{
sum = upper_bound(a,a+n,b[i]);
printf("%d%c",sum-a,i==m-1?'\n':' ');
}
}
return 0;
}
http://codeforces.com/problemset/problem/600/B
----------------------------------------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200010
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int a[MAXN] = {0},i=0,c = 0,*sum,b[MAXN] = {0};
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
for(int i=0;i<m;i++)
scanf("%d",&b[i]);
for(int i=0;i<m;i++)
{
sum = upper_bound(a,a+n,b[i]);
printf("%d%c",sum-a,i==m-1?'\n':' ');
}
}
return 0;
}
留言
張貼留言