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

    解题思路:STL —— vector, map

     1 ///////////////////////////////////////////////////////////////////////////
     2 //problem_id: uva 11991
     3 //user_id: SCNU20102200088
     4 ///////////////////////////////////////////////////////////////////////////
     5 
     6 #include <algorithm>
     7 #include <iostream>
     8 #include <iterator>
     9 #include <iomanip>
    10 #include <cstring>
    11 #include <cstdlib>
    12 #include <string>
    13 #include <vector>
    14 #include <cstdio>
    15 #include <cctype>
    16 #include <cmath>
    17 #include <queue>
    18 #include <stack>
    19 #include <list>
    20 #include <set>
    21 #include <map>
    22 using namespace std;
    23 
    24 ///////////////////////////////////////////////////////////////////////////
    25 #pragma comment(linker,"/STACK:1024000000,1024000000")
    26 
    27 #define lson l,m,rt<<1
    28 #define rson m+1,r,rt<<1|1
    29 ///////////////////////////////////////////////////////////////////////////
    30 
    31 ///////////////////////////////////////////////////////////////////////////
    32 const double EPS=1e-8;
    33 const double PI=acos(-1.0);
    34 
    35 const int x4[]={-1,0,1,0};
    36 const int y4[]={0,1,0,-1};
    37 const int x8[]={-1,-1,0,1,1,1,0,-1};
    38 const int y8[]={0,1,1,1,0,-1,-1,-1};
    39 ///////////////////////////////////////////////////////////////////////////
    40 
    41 ///////////////////////////////////////////////////////////////////////////
    42 typedef long long LL;
    43 
    44 typedef int T;
    45 T max(T a,T b){ return a>b? a:b; }
    46 T min(T a,T b){ return a<b? a:b; }
    47 T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
    48 T lcm(T a,T b){ return a/gcd(a,b)*b; }
    49 ///////////////////////////////////////////////////////////////////////////
    50 
    51 ///////////////////////////////////////////////////////////////////////////
    52 //Add Code:
    53 vector<int> a[1000005];
    54 ///////////////////////////////////////////////////////////////////////////
    55 
    56 int main(){
    57     ///////////////////////////////////////////////////////////////////////
    58     //Add Code:
    59     int n,m,x,k,v,i;
    60     while(scanf("%d%d",&n,&m)!=EOF){
    61         for(i=0;i<=1000000;i++) a[i].clear();
    62         for(i=1;i<=n;i++){
    63             scanf("%d",&x);
    64             a[x].push_back(i);
    65         }
    66         while(m--){
    67             scanf("%d%d",&k,&v);
    68             if(a[v].size()<k) printf("0
    ");
    69             else printf("%d
    ",a[v][k-1]);
    70         }
    71     }
    72     ///////////////////////////////////////////////////////////////////////
    73     return 0;
    74 }
    75 
    76 ///////////////////////////////////////////////////////////////////////////
    77 /*
    78 Testcase:
    79 Input:
    80 8 4
    81 1 3 2 2 4 3 2 1
    82 1 3
    83 2 4
    84 3 2
    85 4 2
    86 Output:
    87 2
    88 0
    89 7
    90 0
    91 */
    92 ///////////////////////////////////////////////////////////////////////////

     1 ///////////////////////////////////////////////////////////////////////////
     2 //problem_id: uva 11991
     3 //user_id: SCNU20102200088
     4 ///////////////////////////////////////////////////////////////////////////
     5 
     6 #include <algorithm>
     7 #include <iostream>
     8 #include <iterator>
     9 #include <iomanip>
    10 #include <cstring>
    11 #include <cstdlib>
    12 #include <string>
    13 #include <vector>
    14 #include <cstdio>
    15 #include <cctype>
    16 #include <cmath>
    17 #include <queue>
    18 #include <stack>
    19 #include <list>
    20 #include <set>
    21 #include <map>
    22 using namespace std;
    23 
    24 ///////////////////////////////////////////////////////////////////////////
    25 #pragma comment(linker,"/STACK:1024000000,1024000000")
    26 
    27 #define lson l,m,rt<<1
    28 #define rson m+1,r,rt<<1|1
    29 ///////////////////////////////////////////////////////////////////////////
    30 
    31 ///////////////////////////////////////////////////////////////////////////
    32 const double EPS=1e-8;
    33 const double PI=acos(-1.0);
    34 
    35 const int x4[]={-1,0,1,0};
    36 const int y4[]={0,1,0,-1};
    37 const int x8[]={-1,-1,0,1,1,1,0,-1};
    38 const int y8[]={0,1,1,1,0,-1,-1,-1};
    39 ///////////////////////////////////////////////////////////////////////////
    40 
    41 ///////////////////////////////////////////////////////////////////////////
    42 typedef long long LL;
    43 
    44 typedef int T;
    45 T max(T a,T b){ return a>b? a:b; }
    46 T min(T a,T b){ return a<b? a:b; }
    47 T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
    48 T lcm(T a,T b){ return a/gcd(a,b)*b; }
    49 ///////////////////////////////////////////////////////////////////////////
    50 
    51 ///////////////////////////////////////////////////////////////////////////
    52 //Add Code:
    53 ///////////////////////////////////////////////////////////////////////////
    54 
    55 int main(){
    56     ///////////////////////////////////////////////////////////////////////
    57     //Add Code:
    58     int n,m,x,k,v,i;
    59     while(scanf("%d%d",&n,&m)!=EOF){
    60         map<int,vector<int> > a;
    61         for(i=1;i<=n;i++){
    62             scanf("%d",&x);
    63             if(a.count(x)==0) a[x]=vector<int>();
    64             a[x].push_back(i);
    65         }
    66         while(m--){
    67             scanf("%d%d",&k,&v);
    68             if(a.count(v)==0 || a[v].size()<k) printf("0
    ");
    69             else printf("%d
    ",a[v][k-1]);
    70         }
    71     }
    72     ///////////////////////////////////////////////////////////////////////
    73     return 0;
    74 }
    75 
    76 ///////////////////////////////////////////////////////////////////////////
    77 /*
    78 Testcase:
    79 Input:
    80 8 4
    81 1 3 2 2 4 3 2 1
    82 1 3
    83 2 4
    84 3 2
    85 4 2
    86 Output:
    87 2
    88 0
    89 7
    90 0
    91 */
    92 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    ArrayList类(转)
    通过XmlDocument读写Xml文档(转)
    js的一些常用方法
    和我一起恶补pl/sql(第三讲)
    js的跑步算法
    细说 Form (表单)(转)
    C#反射设置和读取类的属性
    显示最近30天的记录vs显示这个月的记录(pl\sql)
    nyist 637 我和你
    nyist 子串和
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3313089.html
Copyright © 2011-2022 走看看