zoukankan      html  css  js  c++  java
  • 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
    ",mp[ans]);
               mp[ans]=0;
           }
           else
            printf("0
    ");
       }
       }
        return 0;
    }

    注意点:

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

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

  • 相关阅读:
    jsp中一个标签两种方式绑定两个click事件导致未执行的问题
    Chrome浏览器自动填充<input>标签的密码
    js中字符串的replace方法区分单双引号
    注册页面-省市联动
    mac OS X下制定ll指令
    ssh通过密钥免密登录linux服务器
    mac OS X下PhpStorm+MAMP PRO+Xdebug+FireFox集成开发和断点调试环境配置
    ubuntn配置桌面快捷方式
    centos安装Redis
    Spring文件下载与上传 FormData
  • 原文地址:https://www.cnblogs.com/zuiaimiusi/p/10884091.html
Copyright © 2011-2022 走看看