zoukankan      html  css  js  c++  java
  • 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
    ",c-d);
    46         }       
    47     }
    48     
    49     
    50     return 0;
    51 }
  • 相关阅读:
    Circular vector
    【杂题】进制转换
    【POJ】3006
    【POJ】1503
    【POJ】2262
    【POJ】1083
    【POJ】2739
    对拍
    【POJ】2159
    【POJ】3299
  • 原文地址:https://www.cnblogs.com/sxiszero/p/4417079.html
Copyright © 2011-2022 走看看