zoukankan      html  css  js  c++  java
  • codeforces C. Design Tutorial: Make It Nondeterministic

    题意:每一个人 都有frist name 和 last name! 从每一个人的名字中任意选择
    first name 或者 last name 作为这个人的编号!通过对编号的排序,得到每一个人
    最终顺序!比较中的序列能否得到给定输出的序列一致!

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<string>
     5 #include<map>
     6 #include<algorithm>
     7 #define N 100005
     8 using namespace std;
     9 
    10 int p[N];
    11 string name[2*N];
    12 map<string, int>mp;//将每一个人名字映射到是第几个人 
    13 
    14 
    15 int main(){
    16     int n; 
    17     int cnt=0;
    18     cin>>n;
    19     for(int i=1; i<=n; ++i){
    20         cin>>name[cnt++]>>name[cnt++];
    21         mp.insert(make_pair(name[cnt-2], i));
    22         mp.insert(make_pair(name[cnt-1], i));
    23     }
    24     for(int i=1; i<=n; ++i)//每个人的排序之后的序列 
    25         cin>>p[i]; 
    26     sort(name, name+cnt);//排序 
    27     int k = 1;
    28     for(int i=0; i<cnt; ++i)//贪心 
    29         if(mp[name[i]] == p[k]){
    30             ++k;
    31             if( k > n) break;
    32         }
    33     if(k>n) cout<<"YES";
    34     else cout<<"NO";
    35     cout<<endl;      
    36     return 0;
    37 }
    View Code
  • 相关阅读:
    关于背包DP的几点总结
    C++ P1510 精卫填海
    C++ P1060 开心的金明
    C++ P2613 【模板】有理数取余
    C++ P3811 【模板】乘法逆元
    C++ P1865 A % B Problem
    【转】char码值对应列表大全
    JDK和JVM
    如何打包成jar包自己看呢?
    java的真相
  • 原文地址:https://www.cnblogs.com/hujunzheng/p/3999975.html
Copyright © 2011-2022 走看看