BestCoder Round #36 [B] Gunner

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5199

先对树的高度排序,然后对每次射击高度二分查找即可,打过之后数目变为0。

 1 #include<cstdio>

 2 #include<iostream>

 3 #include<string.h>

 4 #include<algorithm>

 5 #include<math.h>

 6 #include<stdbool.h>

 7 #include<time.h>

 8 #include<stdlib.h>

 9 #include<set>

10 #include<map>

11 #include<stack>

12 #include<queue>

13 #include<vector>

14 using namespace std;

15 #define clr(x,y)    memset(x,y,sizeof(x))

16 #define sqr(x)      ((x)*(x))

17 #define rep(i,a,b)  for(int i=(a);i<=(b);i++)

18 #define LL          long long

19 #define INF         0x3f3f3f3f

20 #define A           first

21 #define B           second

22 #define PI          acos(-1.0)

23 const int N=1e6+131;

24 

25 int n,m,x,h[N],q[N];

26 

27 void init()

28 {

29     clr(h,0);

30     clr(q,0);

31 }

32 

33 int  main()

34 {

35     while(~scanf("%d%d",&n,&m)) {

36         init();

37         rep(i,0,n-1) scanf("%d",&h[i]);

38         sort(h,h+n);

39         rep(i,0,m-1) {

40             scanf("%d",&x);

41             int c=upper_bound(h,h+n,x)-h;

42             int d=lower_bound(h,h+n,x)-h;

43             if(q[c]) { puts("0"); continue; }

44             q[c]=1; 

45             printf("%d\n",c-d);

46         }       

47     }

48     

49     

50     return 0;

51 }

 

你可能感兴趣的:(round)