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 }
复制代码









本文转自 小眼儿 博客园博客,原文链接:http://www.cnblogs.com/hujunzheng/p/3999975.html,如需转载请自行联系原作者
目录
相关文章
|
Perl
AtCoder Beginner Contest 217 F - Make Pair (区间dp)
AtCoder Beginner Contest 217 F - Make Pair (区间dp)
94 0
Design Tutorial: Learn from Math
Design Tutorial: Learn from Math
47 0
Design Tutorial: Learn from Math
【HDU 5572 An Easy Physics Problem】计算几何基础
2015上海区域赛现场赛第5题。 题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5572 题意:在平面上,已知圆(O, R),点B、A(均在圆外),向量V。
1000 0