您的位置:首页 > 其它

Uva-11991 - Easy Problem from Rujia Liu?

2016-10-18 11:33 423 查看


题目大意:求第k个v的编号

方法很多,这里给出比较快的,用STL中的map和vector

#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
#include<vector>
using namespace std;
const int N=1000005;
map<int,vector<int> >ma;
int n,m;
int main(){
freopen("Uva.in","r",stdin);
freopen("Uva.out","w",stdout);
while((scanf("%d%d",&n,&m))==2){
ma.clear();
for(int i =1; i<=n;i++){
int x;
scanf("%d",&x);
if(!ma.count(x))ma[x]=vector<int>();//新建vector
ma[x].push_back(i);
}
for(int i = 1; i<= m; i++){
int  k,v;
scanf("%d%d",&k,&v);
if(!ma.count(v) ||ma[v].size()<k)//don't forget the second one
printf("0\n");
else printf("%d\n",ma[v][k-1]);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  STL