您的位置:首页 > 其它

UVa 11991 Easy Problem from Rujia Liu?

2015-03-15 16:42 330 查看
水题。

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

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

#include <cstdio>
#include <map>
#include <vector>
using namespace std;

void scan(int& x)
{
char c;
while(c = getchar(), c < '0' || c > '9');
x = c - '0';
while(c = getchar(), c >= '0' && c <= '9') x = x*10 + c - '0';
}

const int maxn = 100000 + 10;

int main()
{
//freopen("in.txt", "r", stdin);

int n, m;
while(scanf("%d%d", &n, &m) == 2)
{
map<int, vector<int> > pos;
for(int i = 1; i <= n; i++)
{
int x;
scan(x);
pos[x].push_back(i);
}
for(int i = 0; i < m; i++)
{
int k, v;
scan(k); scan(v);
if(k <= pos[v].size()) printf("%d\n", pos[v][k-1]);
else printf("0\n");
}
}

return 0;
}


代码君
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: