C. Design Tutorial: Make It Nondeterministic
来源:互联网 发布:淘宝补差价链接怎么弄 编辑:程序博客网 时间:2024/05/22 17:16
A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a convex hull.
Let's try to make a new task. Firstly we will use the following task. There are n people, sort them by their name. It is just an ordinary sorting problem, but we can make it more interesting by adding nondeterministic element. There are n people, each person will use either his/her first name or last name as a handle. Can the lexicographical order of the handles be exactly equal to the given permutation p?
More formally, if we denote the handle of the i-th person as hi, then the following condition must hold: .
The first line contains an integer n (1 ≤ n ≤ 105) — the number of people.
The next n lines each contains two strings. The i-th line contains strings fi and si (1 ≤ |fi|, |si| ≤ 50) — the first name and last name of the i-th person. Each string consists only of lowercase English letters. All of the given 2n strings will be distinct.
The next line contains n distinct integers: p1, p2, ..., pn (1 ≤ pi ≤ n).
If it is possible, output "YES", otherwise output "NO".
3gennady korotkevichpetr mitrichevgaoyuan chen1 2 3
NO
3gennady korotkevichpetr mitrichevgaoyuan chen3 1 2
YES
2galileo galileinicolaus copernicus2 1
YES
10rean schwarzerfei claussellalisa reinfordeliot craiglaura arseidjusis albareamachias regnitzsara valestinemma millsteingaius worzel1 2 3 4 5 6 7 8 9 10
NO
10rean schwarzerfei claussellalisa reinfordeliot craiglaura arseidjusis albareamachias regnitzsara valestinemma millsteingaius worzel2 4 9 6 5 7 1 3 8 10
YES
In example 1 and 2, we have 3 people: tourist, Petr and me (cgy4ever). You can see that whatever handle is chosen, I must be the first, then tourist and Petr must be the last.
In example 3, if Copernicus uses "copernicus" as his handle, everything will be alright.
解题说明:题目的意思是每一个人 都有frist name 和 last name。 从每一个人的名字中任意选择first name 或者 last name 作为这个人的编号,通过对编号的排序,得到每一个人的最终顺序,比较中的序列能否得到给定输出的序列一致。字符串处理题,对字符串进行排序即可。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<cmath>#include<cstdlib>using namespace std;int N;string a[100100],b[100100];string cur="";int p[100100];int main(){int i,x;cin>>N;for(i=0;i<N;i++) {cin>>a[i]>>b[i];}for(i=0;i<N;i++){cin>>p[i];p[i]--;}for(i=0;i<N;i++){x=p[i];if(a[x]>b[x]){swap(a[x],b[x]);}if(cur<a[x]){cur=a[x];}else if(cur<b[x]) {cur=b[x];}else{cout<<"NO"<<endl;return 0;}}cout<<"YES"<<endl;return 0;}
- C. Design Tutorial: Make It Nondeterministic
- 【CODEFORCES】 C. Design Tutorial: Make It Nondeterministic
- codeforces 472C Design Tutorial: Make It Nondeterministic 贪心
- codeforces 472C. Design Tutorial: Make It Nondeterministic
- Codeforces 472C - Design Tutorial: Make It Nondeterministic(模拟)
- 【codeforces】 472C Design Tutorial: Make It Nondeterministic
- CF 270C - Design Tutorial: Make It Nondeterministic
- codeforces-#472C. Design Tutorial: Make It Nondeterministic(贪心)
- CodeForces 472C Design Tutorial: Make It Nondeterministic (贪心)
- Codeforces 472C Design Tutorial: Make It Nondeterministic
- Codeforces 472C Design Tutorial: Make It Nondeterministic【贪心】
- codeforces 之 Design Tutorial: Make It Nondeterministic
- cf472C Design Tutorial: Make It Nondeterministic
- Codeforces #270 C. Design Tutorial: Make It Nondeterministic(字符串:字符串处理)
- Codeforces Round #270——C. Design Tutorial: Make It Nondeterministic
- Design Patterns Video Tutorial
- Singleton Design Pattern Tutorial
- Tutorial: Make Vim as Your C/C++ IDE Using c.vim Plugin
- IT忍者神龟之使用 PowerDesigner
- 如何快速学会嵌入式?
- 2014ACMICPC亚洲区域赛牡丹江现场赛之旅
- 点筹金融合作指南
- [Java Web]Hibernate基础总结(四)
- C. Design Tutorial: Make It Nondeterministic
- 使用控件时提示"未声明标识符"的解决方法
- android常用命令
- C++中的引用符号“&”
- 路由器广告过滤设置
- 国内外知名互联网公司的口号你知道几个?
- Android中View的绘制过程 onMeasure方法简述 附有自定义View例子
- .net获取系统当前时间
- 委托、事件与Observer设计模式——学习笔记