码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 11991 Easy Problem from Rujia Liu?

时间:2014-08-04 13:31:47      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   数据   for   ar   

STL数据结构(vector,map)基本操作

 

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <algorithm>
 5 #include <vector>
 6 #include <map>
 7 using namespace std;
 8 
 9 int main (){
10     int n,m;
11     map <int,vector<int> > x;
12     while (~scanf ("%d%d",&n,&m)){
13         x.clear() ;
14         for (int i=1;i<=n;i++){
15             int a;
16             scanf ("%d",&a);
17             if (!x.count (a))       //判断是否为空;
18                 x[a]=vector<int> {};
19             x[a].push_back (i);
20         }
21         while (m--){
22             int k,v;
23             scanf ("%d%d",&k,&v);//cout<<x[v][k-1]<<endl;
24             if (!x.count(v)||x[v].size()<k)
25                 printf ("0\n");
26             else printf ("%d\n",x[v][k-1]);
27         }
28     }
29     return 0;
30 }

 

UVA 11991 Easy Problem from Rujia Liu?,布布扣,bubuko.com

UVA 11991 Easy Problem from Rujia Liu?

标签:style   blog   color   os   io   数据   for   ar   

原文地址:http://www.cnblogs.com/gfc-g/p/3889534.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!