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< ...
随机推荐
- iOS Swift最简单的Animation
最近发现Animation是一个iOS开发中非常好玩的元素,能给应用的交互性增色不少.比如很多音乐应用的菜单从底部弹出和隐藏的效果. Animation最核心的当然就是UIView的animateWi ...
- 关于 android 开发中 debug不能顺利进行的各种问题的总结
最后一条应该写反了,如果combined hover 取消勾选的话 那么 在写代码时候的悬浮提示就没有了
- 第三次作业——K米评测
第一部分 调研,评测 1.第一次上手体验 其实让我下载一个APP并且长期使用它是一件特别难的事情,不仅是因为占空间,需要注册个人信息,绑定账号,更是因为每款软件的功能虽然都很齐全,但是你并在没有真正用 ...
- Node-webkit简介
Node-webkit 概述 Node-webkit 是Github 上一个非常热门的开源项目,它基于著名的浏览器开源项目 Chromium 和服务器端 JavaScript 实现 Node.js 的 ...
- 利用 Django REST framework 编写 RESTful API
利用 Django REST framework 编写 RESTful API Updateat 2015/12/3: 增加 filter 最近在玩 Django,不得不说 rest_framewor ...
- DockerProblem
if you try to run the daemon manually: sudo /usr/bin/docker daemon And the error is: "FATA[0000 ...
- app的描述
app的描述=需求文档+接口文档+程序架构. 程序架构:类结构图: 需求文档:业务逻辑-->时序图.
- ansible加密命令
ansible-vault用于配置文件加密,如编写的playbook配置文件中包含敏感信息,不希望其他人随意查看,ansible-valut可加密/解密这个配置文件,刚试了下也可以加密txt文档,猜想 ...
- centos 7.0最小化安装 查看yum 所有安装的软件包~
使用命令 yum list installed [root@localhost ~]# yum list installed 已加载插件:fastestmirror base | 3.6 kB 00: ...
- Nginx + spawn-fcgi- Ubuntu中文
Nginx - Ubuntu中文 页面 讨论 查看源代码 历史 导航 首页 最近更改 随机页面 页面分类 帮助 编辑 编辑指南 沙盒 新闻动态 字词处理 工具 链入页面 相关更改 特殊页面 打印版 ...