zoukankan      html  css  js  c++  java
  • uva 11991

    题目链接:uva 11991 - Easy Problem from Rujia Liu?

    题目大意:给出一个包括n个整数的数组,你须要回答若干询问,每次询问两个整数k和v,输出从左到右第k个v的下标

    解题思路:用map映射一个vector,相应即为map<int>即为一个可变长的数组。读取数组的时候将相应值放入就可以。

    #include <cstdio>
    #include <cstring>
    #include <map>
    #include <vector>
    #include <algorithm>
    
    using namespace std;
    map<int, vector<int> > g;
    
    int main () {
        int N, M, x, y;
        while (scanf("%d%d", &N, &M) == 2) {
            g.clear();
            for (int i = 1; i <= N; i++) {
                scanf("%d", &x);
                if (!g.count(x))
                    g[x] = vector<int>();
                g[x].push_back(i);
            }
    
            for (int i = 0; i < M; i++) {
                scanf("%d%d", &x, &y);
                if (!g.count(y) || g[y].size() < x)
                    printf("0
    ");
                else
                    printf("%d
    ", g[y][x-1]);
            }
        }
        return 0;
    }
  • 相关阅读:
    405
    406
    4-1
    3-11
    3-10
    3-9
    3-8
    3-7
    3-5
    3-4
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4607254.html
Copyright © 2011-2022 走看看