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 ...
随机推荐
- CSS 实现行内和上下自适应的几种方法
在写一个移动端网页,发现网页的头部搜索框两边各有固定宽度的按钮,搜索框可以根据宽度的变化来改变自己的宽度,达到填充的目的,也就是一种自适应吧,下面写写自己尝试的几种方法 一 利用css3 的width ...
- [转]Oracle hang分析
hanganalyze是ORACLE的一款性能诊断工具,这个款工具是从oracle 8.0.6开始可用,在oracle数据库出现严重的性能问题的时候它可以帮助你定位问题所在. 1.首先说说hangan ...
- Centos6.4安装Mono和MonoDevelop
Mono官方网站:http://www.mono-project.com MonoDevelop官方网站:http://monodevelop.com/ 注:整个安装过程最好在同一个终端下完成! ...
- div容器内文本对齐--神奇的css
有时候使用一些css往往能达到意想不到的效果 最近需要在页面上显示读取的文本内容,中英文混杂着,我把它们统统抛到div中div设置了宽度,效果是相当糟糕,左对齐,右端长短不一,有的超出长度,有的不够长 ...
- [转]不用安装Oracle Client如何使用PLSQL Developer
本文转自:http://www.cnblogs.com/sleepywang/archive/2009/10/13/1582654.html 1. 下载oracle的客户端程序包(30M) 只需要在O ...
- sql常识-Join
SQL join 用于根据两个或多个表中的列之间的关系,从这些表中查询数据. Join 和 Key 有时为了得到完整的结果,我们需要从两个或更多的表中获取结果.我们就需要执行 join. 数据库中的表 ...
- 开源而又强大的迷你型web服务器推荐
appweb显然是不二之选,看了下最新版,已经到了4了 下载下来,http://appwebserver.org/software/appweb-4.4.4-0-src.tgz,十几M,直接吓傻,离我 ...
- Delegate&Event
Delegate 1.基本类: public class Student { public int Id { get; set; } public string Name { get; set; } ...
- 找不到System.Runtime.Serialization.Json的解决方案
System.ServiceModel System.ServiceModel.Web System.Runtime.Serialization 三者均要添加引用
- JavaScript 函数的执行过程
每一个JavaScript函数都是Function对象的一个实例, 它有一个仅供JavaScript引擎存取的内部属性[[Scope]]. 这个[[Scope]]存储着一个作用域的集合, 这个集合就叫 ...