hdu 5233 Gunner II (stl vector map)

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
vector<int> a[100000+100];
map <int,int> temp;
int h[100000+100];
int shoot[100000+100];
int main()
{
    int n,m;
    int i,j,k;
    int now;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int t=0;

        for(int i=0;i<=n;i++) a[i].clear();
        temp.clear();

        for(i=1;i<=n;i++)
        {
            scanf("%d",&h[i]);//vec.push_back(a);
        }

        for(i=1;i<=m;i++)
        {
            scanf("%d",&shoot[i]);
        }

        for(i=n;i>=1;i--)
        {
            now=h[i];
            if(a[temp[now]].empty())
            {
               temp[now]=++t;
              // printf("%d...
",now);
            }
            //printf("*.......*
");
            a[temp[now]].push_back(i);
        }
        //printf("%d!!!
",a[2][a[2].size()-1]);

        for(i=1;i<=m;i++)
        {
             now=temp[shoot[i]];
             if(!a[now].empty())
             {
                 int neww;
                 neww=a[now][a[now].size()-1];
                 a[now].pop_back();
                 printf("%d
",neww);
             }
             else
             {
                 printf("-1
");
             }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/sola1994/p/4630491.html