首页 > 其他 > 详细

UVa 11991 Easy Problem from Rujia Liu?

时间:2015-03-15 18:05:53      阅读:209      评论:0      收藏:0      [点我收藏+]

水题。

给出一个数列,求第k个值为v的数字的位置。

熟练使用STL还是很有必要的,尤其是CF的Div用map用得挺多的。

技术分享
 1 #include <cstdio>
 2 #include <map>
 3 #include <vector>
 4 using namespace std;
 5 
 6 void scan(int& x)
 7 {
 8     char c;
 9     while(c = getchar(), c < 0 || c > 9);
10     x = c - 0;
11     while(c = getchar(), c >= 0 && c <= 9) x = x*10 + c - 0;
12 }
13 
14 const int maxn = 100000 + 10;
15 
16 int main()
17 {
18     //freopen("in.txt", "r", stdin);
19 
20     int n, m;
21     while(scanf("%d%d", &n, &m) == 2)
22     {
23         map<int, vector<int> > pos;
24         for(int i = 1; i <= n; i++)
25         {
26             int x;
27             scan(x);
28             pos[x].push_back(i);
29         }
30         for(int i = 0; i < m; i++)
31         {
32             int k, v;
33             scan(k); scan(v);
34             if(k <= pos[v].size()) printf("%d\n", pos[v][k-1]);
35             else printf("0\n");
36         }
37     }
38 
39     return 0;
40 }
代码君

 

UVa 11991 Easy Problem from Rujia Liu?

原文:http://www.cnblogs.com/AOQNRMGYXLMV/p/4340004.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!