题目地址: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 }

转载于:https://www.cnblogs.com/sxiszero/p/4417079.html

BestCoder Round #36 [B] Gunner相关推荐

  1. BestCoder Round #36

    A:签到题,注意情况都考虑全了判断即可 B:hash树高,统计即可,要加读入挂(略坑) C:离线操作,把询问和树高都从大到小排序,然后砍树变成加树,每次把超过当前询问的树都加进去,每次加树就和左右边判 ...

  2. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢? 可以用矩阵快速幂来加速计算. 我们可以用矩阵来表示数列递推公式 比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [ ...

  3. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 1 /* 2 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 3 当然有可能两个数和超过p,那么an ...

  4. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 1 /* 2 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 3 否则再在tot里减去多余的即为答案 4 用set容器也可以做,思 ...

  5. 字符串处理 BestCoder Round #43 1001 pog loves szh I

    题目传送门 1 /* 2 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 3 */ 4 #include <cstdio&g ...

  6. hdu4585 amp; BestCoder Round #1 项目管理(vector应用)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 项目管理 Time Limit: 2000/1000 MS (Java/Others)    M ...

  7. hdu4932 Miaomiao#39;s Geometry (BestCoder Round #4 枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 Miaomiao's Geometry Time Limit: 2000/1000 MS (Ja ...

  8. HDU 5228 ZCC loves straight flush( BestCoder Round #41)

    题目链接:ZCC loves straight flush 题面: ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others)    ...

  9. BestCoder Round #90 Kblack loves flag

     BestCoder Round #90 Kblack loves flag 问题描述 kblack喜欢旗帜(flag),他的口袋里有无穷无尽的旗帜. 某天,kblack得到了一个n∗mn*mn∗ ...

最新文章

  1. 自定义注解妙用,一行代码搞定用户操作日志记录
  2. springer link:find the journals you need
  3. How to start MySQL on Linux
  4. hive2solr问题小结
  5. SAP Commerce Cloud portal 的 deployment
  6. 51nod-猴猴吃香蕉【dp】
  7. 带有JAX-WS和Spring的Web服务应用程序
  8. 关于微型计算机的原理 叙述正确的是,微型计算机原理练习附答案概念.doc
  9. java将数字转化为指定类型[float保留小数点确定、数字前加0]
  10. 记录pageHelper分页orderby的坑
  11. php实现求对称二叉树(先写思路,谋而后动)
  12. idea连接docker实现一键部署
  13. USB大容量存储设备无法启动--这个设备(服务)的驱动程序已被禁用。另一个驱动程序可以提供这个功能。
  14. 【转】京东抢购服务高并发实践
  15. 记录我的LINUX学习之路
  16. 聪明的猴子(BZOJ 2429)
  17. loadrunner入门篇 - Vuser发生器
  18. 从事大数据征信行业,你必须知道这些
  19. 自定义UI 基础知识
  20. 人工智能Java SDK:基于BERT QA模型问答

热门文章

  1. How To Install IonCube Loader
  2. FlashFXP列表参数错误解决方法
  3. 修改windows XP/2000/2003用缩略图方式浏览图片时的默认尺寸
  4. IBM DB2 Intelligent for Data/Text Version 6
  5. Debian下RPM包安装
  6. (18) HTML面试题集锦2
  7. DJL | DJL 如何正确打开 [ 深度学习 ]
  8. oracle数据库中的系统自带表情_Oracle数据库自带表空间的详细说明
  9. pause容器作用_容器编排之战(四)连载
  10. matlab randi 函数,MATLAB中的randi函数