hdoj 5199 Gunner map

Gunner

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5199

Description

Long long ago, there is a gunner whose name is Jack. He likes to go hunting very much. One day he go to the grove. There are n birds and n trees. The i−th bird stands on the top of the i−th tree. The trees stand in straight line from left to the right. Every tree has its height. Jack stands on the left side of the left most tree. When Jack shots a bullet in height H to the right, the bird which stands in the tree with height H will falls.
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

There are multiple test cases (about 5), every case gives n,m in the first line, n indicates there are n trees and n birds, m means Jack will shot m times.

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

For each q[i], output an integer in a single line indicates the number of birds Jack shot down.

Sample Input

4 3 1 2 3 4 1 1 4

Sample Output

1 0 1

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=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        g.clear();
        for(int i=0;i<n;i++)
        {
            int x=read();
            g[x]++;
        }
        for(int i=0;i<m;i++)
        {
            int x=read();
            if(g.find(x)==g.end())
            {
                printf("0\n");
            }
            else
            {
                printf("%d\n",g[x]);
                g[x]=0;
            }
        }
    }
}
时间: 2024-08-08 13:51:08

hdoj 5199 Gunner map的相关文章

STL HDOJ 5199 Gunner

题目传送门 1 /* 2 题意:问值为x的个数有几个,第二次查询就是0 3 lower/upper_bound ()函数的使用,map也可过,hash方法不会 4 */ 5 #include <cstdio> 6 #include <cmath> 7 #include <cstring> 8 #include <algorithm> 9 #include <iostream> 10 #include <vector> 11 #incl

STL HDOJ 5233 Gunner II

题目传送门 1 /* 2 题意:查询x的id,每次前排的树倒下 3 使用lower_bound ()查找高度,f[i]记录第一棵高度为x树的位置,查询后+1(因为有序) 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 using namespace std; 9 10 const int MAXN = 1e5 + 10; 11 const int INF = 0x3f3f3f3

hdu 5199 Gunner(STL之map,水)

Problem Description Long long ago, there is a gunner whose name is Jack. He likes to go hunting very much. One day he go to the grove. There are n birds and n trees. The i−thbird stands on the top of the i−th tree. The trees stand in straight line fr

hdu 5199 Gunner

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5199 简单题,stl水之... 1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<set> 7 #include<map> 8 using std::m

HDU - 5198 - Strange Class &amp;&amp; 5199 - Gunner

Strange Class Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 74    Accepted Submission(s): 60 Problem Description In Vivid's school, there is a strange class(SC). In SC, the students' names ar

hdu 5199 Gunner (hash || 排序+二分)

题意:有n个不同高度的树排成一列,树上各有1只鸟. 然后m个询问,每次询问可以打掉h[i](1<=i<=m)高度的所有鸟,问m个询问中的各高度能打掉多少只鸟. 分析: 1.题目给了提示要 “快速读入”  咩~ 2.排序+二分 这里可以两次二分(lower_bound找下界,upper_bound找上界) 也可以合并+二分(合并相同的数字,记录次数) g++提交要用#include<stdio.h> 不要用#include<cstdio> 后者有效率问题,会 tle (⊙

HDOJ 2072(map)

#include<cstdio> #include<iostream> #include<vector> #include<map> #include<queue> #include<algorithm> #include<deque> #include<cmath> #include<set> #include<cstring> #include<string> using

【map】【HDOJ】5233 Gunner II

http://acm.hdu.edu.cn/showproblem.php?pid=5233 外面有很多树,每棵树顶上有一只鸟,一个数组按从近到远的顺序列出这些树的高度(也就是鸟的高度) 猎人开始从不同高度打枪,子弹不能穿过鸟,也就是在同一高度上只有最近的鸟会被打下来. 给出一个数组表示猎人每次打枪的高度,要求出每次打落的鸟所在的树的编号(从1开始编号),如果这个高度上没有鸟输出-1 放一个MAP表示每个高度上从近到远的鸟的位置编号, 猎人每次射击就将该高度的定位数向后移,直到定位数大于鸟的数量

Gunner II(二分,map,数字转化)

Gunner II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1740    Accepted Submission(s): 635 Problem Description Long long ago, there was a gunner whose name is Jack. He likes to go hunting ve