Codeforces Round #270 1003
Codeforces Round #270 1003
C. Design Tutorial: Make It Nondeterministic
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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:
.
Input
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).
Output
If it is possible, output "YES", otherwise output "NO".
Sample test(s)
Input
3
gennady korotkevich
petr mitrichev
gaoyuan chen
1 2 3
Output
NO
Input
3
gennady korotkevich
petr mitrichev
gaoyuan chen
3 1 2
Output
YES
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; int n;
pair<string,int> mp[]; int main()
{
scanf("%d",&n);
for(int i = ;i<=(n<<);i++)
{
cin>>mp[i].first;
mp[i].second = (i+)/;
}
sort(mp+,mp+*n+);
int rk;
int j = ;
int ct = ;
for(int i = ;i<=n;i++)
{
scanf("%d",&rk);
for(;j<=*n;j++)
{
if(mp[j].second==rk)
{
ct++;
break;
}
}
}
if(ct==n) puts("YES");
else puts("NO");
return ;
}
Codeforces Round #270 1003的更多相关文章
- Codeforces Round #270 1002
Codeforces Round #270 1002 B. Design Tutorial: Learn from Life time limit per test 1 second memory l ...
- Codeforces Round #270 1001
Codeforces Round #270 1001 A. Design Tutorial: Learn from Math time limit per test 1 second memory l ...
- Codeforces Round #270 A~D
Codeforces Round #270 A. Design Tutorial: Learn from Math time limit per test 1 second memory limit ...
- Codeforces Round #270(利用prim算法)
D. Design Tutorial: Inverse the Problem time limit per test 2 seconds memory limit per test 256 mega ...
- codeforces水题100道 第七题 Codeforces Round #270 A. Design Tutorial: Learn from Math (math)
题目链接:http://www.codeforces.com/problemset/problem/472/A题意:给你一个数n,将n表示为两个合数(即非素数)的和.C++代码: #include & ...
- 多种方法过Codeforces Round #270的A题(奇偶法、打表法和Miller_Rabin(这个方法才是重点))
题目链接:http://codeforces.com/contest/472/problem/A 题目: 题意:哥德巴赫猜想是:一个大于2的素数一定可以表示为两个素数的和.此题则是将其修改为:一个大于 ...
- Codeforces Round #270 D Design Tutorial: Inverse the Problem --MST + DFS
题意:给出一个距离矩阵,问是不是一颗正确的带权树. 解法:先按找距离矩阵建一颗最小生成树,因为给出的距离都是最短的点间距离,然后再对每个点跑dfs得出应该的dis[][],再对比dis和原来的mp是否 ...
- Codeforces Round #270 D C B A
谈论最激烈的莫过于D题了! 看过的两种做法不得不ORZ,特别第二种,简直神一样!!!!! 1th:构造最小生成树. 我们提取所有的边出来按边排序,因为每次我们知道边的权值>0, 之后每次把边加入 ...
- Codeforces Round #270
A 题意:给出一个数n,求满足a+b=n,且a+b均为合数的a,b 方法一:可以直接枚举i,n-i,判断a,n-i是否为合数 #include<iostream> #include< ...
随机推荐
- 通过oauth 认证 新浪微博 开发过程中遇到的问题
1 Android之NetworkOnMainThreadException异常 http://blog.csdn.net/mad1989/article/details/25964495 ,从Hon ...
- java循环遍历map
import java.util.HashMap; import java.util.Iterator; import java.util.Map; public class MapTest { pu ...
- C#和Javascript的try…catch…finally的一点差别
C#中规定:如果程序的控制流进入了一个带finally块的try语句,那么finally语句块始终会被执行 例子: class Program { static void Main(string[] ...
- 在Ubuntu上如何往fcitx里添加输入法
Ubuntu 16.04引入了一个新的包管理工具apt, 用法与apt-get类似. 在终端用apt搜索fcitx支持的输入法 apt search fcitx All Fcitx related p ...
- HDU 1022 Train Problem I(栈模拟)
传送门 Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of st ...
- Java 序列化Serializable接口
1 什么是序列化和反序列化 Serialization(序列化)是一种将对象以一连串的字节描述的过程:反序列化deserialization是一种将这些字节重建成一个对象的过程. 2 什么情况下需要 ...
- canvas练习
<!doctype html><html><head><meta charset="utf-8"><title>move ...
- arcglobe 图层三大类说明
若是第一次打开,且在网络连接通畅的情况下,你会发现目录中已有部分数据层,这些数据层是由ArcGIS Online的在线数据:Imagery图层即在线的影像数据.高程数据.地名数据.运输线数据. Arc ...
- bs4_2
QQ:231469242 欢迎交流 Parsing HTML with the BeautifulSoup Module Beautiful Soup是用于提取HTML网页信息的模板,Beautif ...
- XtraFinder在OSX10.11的使用
重启系统,按住command键加上R键 进入恢复模式还是什么模式里,然后启动terminal 然后键入 csrutil enable --without debug 重启电脑,可正常使用 居然上传不了 ...