zoukankan      html  css  js  c++  java
  • UVa 11991 Easy Problem from Rujia Liu?

    水题。

    给出一个数列,求第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
    ", pos[v][k-1]);
    35             else printf("0
    ");
    36         }
    37     }
    38 
    39     return 0;
    40 }
    代码君
  • 相关阅读:
    数据库存储语句
    数据库练习总结
    数据库练习
    数据库增添
    数据库创建
    cookie 和 session的区别 & 三种传值方式
    内置对象——cookie
    webform跨页面传值
    复合控件
    repeater(控件)数据展示
  • 原文地址:https://www.cnblogs.com/AOQNRMGYXLMV/p/4340004.html
Copyright © 2011-2022 走看看