hdu5199(map 离散化)

Gunner

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 nn birds and nn trees. The ithi−th bird stands on the top of the ithi−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 HH 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 HH .InputThere are multiple test cases (about 5), every case gives n,mn,m in the first line, nn indicates there are nn trees and nn birds, mm means Jack will shot mm times.

In the second line, there are nn numbers h[1],h[2],h[3],,h[n]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]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]

1n,m1000000(106)1≤n,m≤1000000(106)

1h[i],q[i]1000000000(109)1≤h[i],q[i]≤1000000000(109)

All inputs are integers.
OutputFor each q[i]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

 

#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
#include<string.h>
#include<map>
using namespace std;
int n,m,t;
string a,b;
int main()
{
   map<int,int> mp;
   int n,m,tot,ans;
   while(~scanf("%d%d",&n,&m)){
   for(int i=0;i<n;i++)
   {
     scanf("%d",&tot);
     mp[tot]++;//鸟的数量增加(树高的数量就是鸟的数量)
   }
   for(int i=0;i<m;i++)
   {
       scanf("%d",&ans);
       if(mp.find(ans)!=mp.end())//查找键
       {
           printf("%d\n",mp[ans]);
           mp[ans]=0;
       }
       else
        printf("0\n");
   }
   }
    return 0;
}

注意点:

1.一开始超时,换成printf就好了。以后都用printf。

2.if(mp.find(ans)!=mp.end())//查找键

转载于:https://www.cnblogs.com/zuiaimiusi/p/10884091.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值