首页 > 代码库 > uva 11991 (map vector 嵌套)

uva 11991 (map vector 嵌套)

 

其实这题可以直接用vector

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<map>#include<vector>using namespace std;vector<int> str[1000000+100];int main(){    int n,m;    int i,j,k;    int que,num,temp;    while(scanf("%d%d",&n,&m)!=EOF)    {        memset(str,0,sizeof(str));        for(i=1;i<=n;i++)        {            scanf("%d",&temp);            str[temp].push_back(i);        }        for(i=1;i<=m;i++)        {            scanf("%d%d",&que,&num);            if(str[num].size()>=que)            printf("%d\n",str[num][que-1]);            else printf("0\n");        }    }    return 0;}

 

大白上的代码

#include<cstdio>#include<vector>#include<map>using namespace std;map<int ,vector<int> > a;int main(){    int n,m,x,y;    while(scanf("%d%d",&n,&m)==2)    {        a.clear();        for(int i=0;i<n;i++)        {            scanf("%d",&x);            if(!a.count(x)) a[x]=vector <int>();            a[x].push_back(i+1);        }        while(m--)        {            scanf("%d%d",&x,&y);            if(!a.count(y)||a[y].size()<x) printf("0\n");            else printf("%d\n",a[y][x-1]);        }    }    return 0;}

 

uva 11991 (map vector 嵌套)