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

UVa 11991 Easy Problem from Rujia Liu?

时间:2015-03-15 18:07:35      阅读:107      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!