zoukankan      html  css  js  c++  java
  • hdu 5233 Gunner II 离散化

    Gunner II

    Time Limit: 20 Sec  Memory Limit: 256 MB

    题目连接

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

    Description

    很久很久以前,有一个叫Jack的枪手。他非常喜欢打猎。一天,他去了一个小树林。那儿有n只鸟,还有n棵树。第i只鸟站在第i棵树的顶端。这些树从左到右排成一条直线。每一棵树都有它的高度。Jack站在最左边那棵树的左边。当Jack在高度为H的地方向右发射一棵子弹时,站在高度为H的树上且离Jack最近的鸟儿就会落下来。 Jack会射击多次,他想知道每次射击哪只鸟儿会落下来。

    Input

    多组测试数据(大概5组),每一组的第一行给出n,m,n表示有n棵树和n只鸟,m表示Jack会射击m次。 在第二行,有n个整数h[1],h[2],h[3],…,h[n]表示这些树的高度。 在第三行,有m个整数,q[1],q[2],q[3],…,q[m]表示Jack射击的高度。 [参数约定] 所有输入均为整数。 1<=n,m<=100000(10^5) 1<=h[i],q[i]<=1000000000(10^9)

    Output

    对于每一个q[i],在一行中输出Jack射落的鸟的id。如果没有射中鸟儿,请输出-1。 (id 从1开始编号。)

    Sample Input

    5 5 1 2 3 4 1 1 3 1 4 2

    Sample Output

    1 3 5 4 2

    HINT

    题意

    题解:

    离散化离散化!

    搞搞搞,就变成傻逼题了!

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    int Num;
    char CH[20];
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    /*
    
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    */
    inline ll read()
    {
        ll 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;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    //**************************************************************************************
    
    struct node
    {
        int x,y;
    };
    node h[maxn];
    int q[maxn];
    map<int,int> H;
    vector<int> k;
    vector<int> dp[maxn];
    int cnt[maxn];
    int main()
    {
        //freopen("test.txt","r",stdin);
        int n,m;
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            memset(h,0,sizeof(h));
            memset(q,0,sizeof(q));
            H.clear();
            k.clear();
            for(int i=0;i<maxn;i++)
                dp[i].clear();
            memset(cnt,0,sizeof(cnt));
            for(int i=0;i<n;i++)
            {
                h[i].x=read();
                h[i].y=i+1;
                k.push_back(h[i].x);
            }
            for(int i=0;i<m;i++)
            {
                q[i]=read();
                k.push_back(q[i]);
            }
            sort(k.begin(),k.end());
            k.erase(unique(k.begin(),k.end()),k.end());
            for(int i=0;i<k.size();i++)
            {   
                H[k[i]]=i;
            }
            //cout<<endl;
            for(int i=0;i<n;i++)
                dp[H[h[i].x]].push_back(h[i].y);
            for(int i=0;i<m;i++)
            {
                if(cnt[H[q[i]]]>=dp[H[q[i]]].size())
                {
                    printf("-1
    ");
                }
                else
                {
                    printf("%d
    ",dp[H[q[i]]][cnt[H[q[i]]]]);
                    cnt[H[q[i]]]++;
                }
            }
        }
    }
  • 相关阅读:
    Metasploit自动攻击和选择模块攻击详解
    laravel 通过ftp上传的时候报错 Use of undefined constant FTP_BINARY
    Laravel--文件管理及上传自定义目录及文件名
    在从myql服务器上 取消主从关系和重新构建主从关系
    sql 从服务器取消主从复制
    pecl和pear 的区别和联系
    laravel中打印一个sql语句
    laravel 查询数据库first()返回的数据转数组
    [微信小程序]实现一个自定义遮罩层
    分享CSS3里box-shadow属性的使用方法,包括内阴影box-shadow:inset
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4524906.html
Copyright © 2011-2022 走看看