Foreign Exchange
Your non-profit organization (iCORE - international Confederation of Revolver Enthusiasts) coordinates
a very successful foreign student exchange program. Over the last few years, demand has
sky-rocketed and now you need assistance with your task.
The program your organization runs works as follows: All candidates are asked for their original
location and the location they would like to go to. The program works out only if every student has a
suitable exchange partner. In other words, if a student wants to go from A to B, there must be another
student who wants to go from B to A. This was an easy task when there were only about 50 candidates,
however now there are up to 500000 candidates!
Input
The input file contains multiple cases. Each test case will consist of a line containing n – the number
of candidates (1 ≤ n ≤ 500000), followed by n lines representing the exchange information for each
candidate. Each of these lines will contain 2 integers, separated by a single space, representing the
candidate’s original location and the candidate’s target location respectively. Locations will be represented
by nonnegative integer numbers. You may assume that no candidate will have his or her original
location being the same as his or her target location as this would fall into the domestic exchange
program. The input is terminated by a case where n = 0; this case should not be processed.
Output
For each test case, print ‘YES’ on a single line if there is a way for the exchange program to work out,
otherwise print ‘NO’.
Sample Input
10
1 2
2 1
3 4
4 3
100 200
200 100
57 2
2 57
1 2
2 1
10
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
0
Sample Output
YES
NO
#include <iostream>
#include <algorithm>
using namespace std;
int a[500000],b[500000];
int main()
{
int n;
while(cin>>n&&n)
{
for(int i=0; i<n; i++)
cin>>a[i]>>b[i];
int f=1;
sort(a,a+n);
sort(b,b+n);
for(int i=0; i<n; i++)
{
if(a[i]!=b[i])
{
f=0;
break;
}
}
//cout<<f<<endl;
if(f)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
Foreign Exchange的更多相关文章
- Foreign Exchange(交换生换位置)
Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enth ...
- uva 10763 Foreign Exchange <"map" ,vector>
Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enthu ...
- uva 10763 Foreign Exchange(排序比较)
题目连接:10763 Foreign Exchange 题目大意:给出交换学生的原先国家和所去的国家,交换成功的条件是如果A国给B国一个学生,对应的B国也必须给A国一个学生,否则就是交换失败. 解题思 ...
- UVA 10763 Foreign Exchange 出国交换 pair+map
题意:给出很多对数字,看看每一对(a,b)能不能找到对应的(b,a). 放在贪心这其实有点像检索. 用stl做,map+pair. 记录每一对出现的次数,然后遍历看看对应的那一对出现的次数有没有和自己 ...
- [刷题]算法竞赛入门经典(第2版) 5-4/UVa10763 - Foreign Exchange
题意:有若干交换生.若干学校,有人希望从A校到B校,有的想从B到C.C到A等等等等.如果有人想从A到B也刚好有人想从B到A,那么可以交换(不允许一对多.多对一).看作后如果有人找不到人交换,那么整个交 ...
- uva:10763 - Foreign Exchange(排序)
题目:10763 - Foreign Exchange 题目大意:给出每一个同学想要的交换坐标 a, b 代表这位同学在位置a希望能和b位置的同学交换.要求每一位同学都能找到和他交换的交换生. 解题思 ...
- UVA Foreign Exchange
Foreign Exchange Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Your non ...
- UVA 10763 Foreign Exchange
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description Your non- ...
- Foreign Exchange UVA - 10763
Your non-profit organization (iCORE - international Confederation of Revolver Enthusiasts) coordin ...
随机推荐
- React Redux Sever Rendering实战
# React Redux Sever Rendering(Isomorphic JavaScript) ![React Redux Sever Rendering(Isomorphic)入门](ht ...
- 用对象型泛型和ArraysList写一个输入学员信息并展示
题目:录入学员信息并保存,当录入学员的编号为0时结束,展示出学员信息 //student类 public class Student { public int id; public String na ...
- 获取Spring-boot系统环境变量方法
public static ConfigurableApplicationContext context = null; public static void main( String[] args ...
- linux - 文本处理 及 正则表达式
先新建一个文件,并写入一些东西,方便测试, 从passwd里复制几行吧 $ /etc/passwd > passwd t$ ll 总用量 drwxrwxr-x huanghao huanghao ...
- linux-cat/less/more/tail
都可以查看文件 不同点 cat:全部查看不分屏显示 定位到ccc结尾的那行 [root@besttest tmp]# cat yumyum.log|grep ccc$ aaaaaaaaaaaaaaaa ...
- 关于JDK中正则表达式
正则表达式的构造摘要 构造 匹配 字符 x 字符 x \\ 反斜线字符 \0n 带有八进制值 0 的字符 n (0 <= n <= 7) \0nn 带有八进制值 0 的字符 nn ...
- 【杨氏矩阵+勾长公式】POJ 2279 Mr. Young's Picture Permutations
Description Mr. Young wishes to take a picture of his class. The students will stand in rows with ea ...
- hdu 1558 Segment set
Segment set Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 4632 NOIP[2015] 运输计划
4632 NOIP[2015] 运输计划 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 大师 Master 题解 题目描述 Description 公元 2044 ...
- PS基础学习 1---基本工具
1,选框工具: 选择以后对选框中的内容进行修改 ① Shift + 选框 为正方形 ② 选中后鼠标放在选框中对选择范围进行拖动 ③ 移动工具可以拉着选框中的内容移动 ④ ctrl+D取消选框 ⑤单行选 ...