hdoj 5199 Gunner map
Gunner
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5199
Description
Jack will shot many times, he wants to know how many birds fall during each shot.
a bullet can hit many birds, as long as they stand on the top of the tree with height of H.
Input
In the second line, there are n numbers h[1],h[2],h[3],…,h[n] which describes the height of the trees.
In the third line, there are m numbers q[1],q[2],q[3],…,q[m] which describes the height of the Jack’s shots.
Please process to the end of file.
[Technical Specification]
1≤n,m≤1000000(106)
1≤h[i],q[i]≤1000000000(109)
All inputs are integers.
Output
Sample Input
4 3 1 2 3 4 1 1 4
Sample Output
HINT
题意
给你n个数m次询问,问你大小为A的数有多少个,第二次问的时候,就直接输出0就好
题解:
map可过,非常轻松(雾
~\(≧▽≦)/~啦啦啦
代码:
#include<cstdio>
#include<map>
using namespace std;
map<int,int> g;
int n,m;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
g.clear();
for(int i=;i<n;i++)
{
int x=read();
g[x]++;
}
for(int i=;i<m;i++)
{
int x=read();
if(g.find(x)==g.end())
{
printf("0\n");
}
else
{
printf("%d\n",g[x]);
g[x]=;
}
}
}
}
hdoj 5199 Gunner map的更多相关文章
- hdu 5199 Gunner(STL之map,水)
Problem Description Long long ago, there is a gunner whose name is Jack. He likes to go hunting very ...
- hdu 5199 Gunner
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5199 简单题,stl水之... #include<algorithm> #include& ...
- 二分查找 BestCoder Round #36 ($) Gunner
题目传送门 /* 题意:问值为x的个数有几个,第二次查询就是0 lower/upper_bound ()函数的使用,map也可过,hash方法不会 */ #include <cstdio> ...
- 二分查找 BestCoder Round #42 1002 Gunner II
题目传送门 /* 题意:查询x的id,每次前排的树倒下 使用lower_bound ()查找高度,f[i]记录第一棵高度为x树的位置,查询后+1(因为有序) */ #include <cstdi ...
- Gunner II(二分,map,数字转化)
Gunner II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- HDOJ.1800 Flying to the Mars(贪心+map)
Flying to the Mars 点我挑战题目 题意分析 有n个人,每个人都有一定的等级,高等级的人可以教低等级的人骑扫帚,并且他们可以共用一个扫帚,问至少需要几个扫帚. 这道题与最少拦截系统有异 ...
- HDOJ.1113 Word Amalgamation(map)
Word Amalgamation 点我挑战题目 点我一起学习STL-MAP 题意分析 给出字典.之后给出一系列======乱序======单词,要求你查字典,如过这个乱序单词对用有多个有序单词可以输 ...
- HDOJ.1228 A + B (map)
A + B 点我挑战题目 点我一起学习STL-MAP 题意分析 讲字符串和数字用map对应即可 代码总览 /* Title:HDOJ.1228 Author:pengwill Date:2016-11 ...
- HDOJ.2072 单词数(map)
单词数 点我挑战题目 点我一起学习STL-MAP 题意分析 给出一行单词,判断这行有不同种的单词多少个,用map可以轻松解决. 代码总览 /* Title:HDOJ.2072 Author:pengw ...
随机推荐
- JDK 6和JDK 7的intern方法之不同
首先介绍下intern方法: 如果常量池中存在当前字符串, 就会直接返回当前字符串. 如果常量池中没有此字符串, 会将此字符串放入常量池中后, 再返回. 1 2 在<深入理解Java虚拟机> ...
- asterisk控制台取消NOTICE信息
中道拨号方案取消了控制台输出的NOTICE信息: 方法:vim /etc/asterisk/logger.conf;console => notice,warning,error把上面这行取消 ...
- NOIP2002普及T3【产生数】
做完发现居然没人用map搞映射特意来补充一发 很容易看出这是一道搜索题考虑搜索方案,如果按字符串转移,必须存储每种状态,空间复杂度明显会爆炸观察到每一位之间是互不影响的 考虑使用乘法原理搜索出每一位的 ...
- Java---容器基础总结
Java提供了大量持有对象的方式: (1) 数组将数字与对象联系起来. 它保存类型明确的对象,查询对象时,不需要对结果做类型转换.它可以是多维的, 可以保存基本类型的数据. 但是,数组一旦生成,其容量 ...
- Linux下的IPC机制
Linux下的IPC机制 IPC(Inter-Process Communication)是多个进程之间相互沟通的一种方法.在linux下有多种进程间通信的方法. 共享内存 Linux内存共享有多种, ...
- Elasticsearch: 权威指南---基础入门
1.查看方式:GETURL:http://10.10.6.225:9200/?pretty pretty 在任意的查询字符串中增加pretty参数.会让Elasticsearch美化输出JSON结果以 ...
- Filebeat配置paths里,不支持递归所有子目录
这个知识点要牢记哟,不然,牛B吹大了,收不回哈. 官方文档为证: Currently it is not possible to recursively fetch all files in all ...
- CSharp中的?.运算符
在编译chromiumFX工程时候,编译失败,无法正常工作.是运算符 (?.)的错误,经过查找,该运算符 参考NULL 条件运算符(C# 和 Visual Basic) 用于在执行成员访问 (?.) ...
- Ubuntu16.04下HBase的安装与配置
一.环境 os : Ubuntu 16.04 LTS 64bit jdk : 1.8.0_161 hadoop : mysql : hive : hbase: -hadoop2 安装HBase前,系统 ...
- Tomcat --> Cannot create a server using the selected type
今天在eclipse想把之前的Tomcat 6删掉,重新配置一个,不料没有下一步 Cannot create a server using the selected type 这句话出现在窗口上面,应 ...