首页 > 代码库 > [FAFU 1266]STL排序+二分查找

[FAFU 1266]STL排序+二分查找

http://acm.fafu.edu.cn/problem.php?id=1266

 

思路很容易理解:

#include<cstdio>#include<algorithm>using namespace std;int num[1000000];int main(){    int n,m,a;    while(~scanf("%d",&n))    {        for(int i=0;i<n;++i)        {            scanf("%d",&num[i]);        }        scanf("%d",&m);        sort(num,num+n);        for(int i=0;i<m;++i)        {            if(i) putchar(‘ ‘);            scanf("%d",&a);            printf("%d",upper_bound(num,num+n,a)-lower_bound(num,num+n,a));        }        putchar(‘\n‘);    }    return 0;}

  

[FAFU 1266]STL排序+二分查找