10763 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
 
题目思路:只要判断YES就好了。如果是YES的话,那么所有的人物所在地和所有的目的地这两个数组的内容是一样的,只是位置不一样,所以只要把他们排下序。然后两个数组的相同位置相减,当不等于0的时候结束循换输出NO。否则YES
 
 
代码如下:(本人小白,如有说出,望各位海涵)
 
 
 

#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的更多相关文章

  1. Foreign Exchange(交换生换位置)

     Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enth ...

  2. uva 10763 Foreign Exchange <"map" ,vector>

    Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enthu ...

  3. uva 10763 Foreign Exchange(排序比较)

    题目连接:10763 Foreign Exchange 题目大意:给出交换学生的原先国家和所去的国家,交换成功的条件是如果A国给B国一个学生,对应的B国也必须给A国一个学生,否则就是交换失败. 解题思 ...

  4. UVA 10763 Foreign Exchange 出国交换 pair+map

    题意:给出很多对数字,看看每一对(a,b)能不能找到对应的(b,a). 放在贪心这其实有点像检索. 用stl做,map+pair. 记录每一对出现的次数,然后遍历看看对应的那一对出现的次数有没有和自己 ...

  5. [刷题]算法竞赛入门经典(第2版) 5-4/UVa10763 - Foreign Exchange

    题意:有若干交换生.若干学校,有人希望从A校到B校,有的想从B到C.C到A等等等等.如果有人想从A到B也刚好有人想从B到A,那么可以交换(不允许一对多.多对一).看作后如果有人找不到人交换,那么整个交 ...

  6. uva:10763 - Foreign Exchange(排序)

    题目:10763 - Foreign Exchange 题目大意:给出每一个同学想要的交换坐标 a, b 代表这位同学在位置a希望能和b位置的同学交换.要求每一位同学都能找到和他交换的交换生. 解题思 ...

  7. UVA Foreign Exchange

    Foreign Exchange Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Your non ...

  8. UVA 10763 Foreign Exchange

      Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Description Your non- ...

  9. Foreign Exchange UVA - 10763

      Your non-profit organization (iCORE - international Confederation of Revolver Enthusiasts) coordin ...

随机推荐

  1. javaScript入门--引用类型

    前面提到过,引用类型的值便是对象,在ECMAScript中,引用类型是一种数据结构,用于将数据和功能组织在一起,而对象则是某个特定引用类型的实例. var a=new Object(); 上面便声明了 ...

  2. Apache服务器中配置虚拟机的方法

    新浪微博虚拟机开发配置步骤及介绍.1.由于后面虚拟机中需要用到Rewrite所以先编辑Apache的conf目录下的httpd.conf文件.(可根据实际需要操作)添加mod_rewrite.so模块 ...

  3. linux云计算集群架构学习笔记:用户管理和root用户密码重置

    RHEL7用户管理 本节所讲内容: 用户和组的相关配置文件 管理用户和组 RHEL7破解root密码 与windows 相比 LINUX中的用户和账号的作用是一样的. 都是基于用户对访问的资源做控制, ...

  4. [改善Java代码]不推荐使用binarySearch对列表进行检索

    对一个列表进行检索时,我们使用的最多的是indexOf方法,它简单好用,而且也不会出错,虽然它只能检索到第一个符合条件的值,但是我们可以生成子列表后再检索.这样也就可以查找到所有符合条件的值了. Co ...

  5. Eclipse使用Maven创建普通Java工程时错误:Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart:RELEASE from any of the configured repositories.

    报错信息如下: Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart:RELEASE f ...

  6. 转:android 设计模式合集

    转: http://mobile.51cto.com/android-419145.htm

  7. 转载js实现打印功能

    <div id="print">打印的内容</div><a href="javascript:void(0)" onclick=& ...

  8. SAX - DefaultHandler

    org.xml.sax.helpers.DefaultHandler 实现了 org.xml.sax.EntityResolver.org.xml.sax.DTDHandler.org.xml.sax ...

  9. Genymotion安卓模拟器,性能最好

    老笔记本用AndroidSDK自带的模拟器 启动慢 运行卡 用了Genymotion启动快,运行响应媲美真机 想起学生时代,那时候智能手机还未完全普及 也用模拟器玩过”电脑里的手机“.

  10. jQuery 的插件 dataTables

    ---恢复内容开始--- jQuery 的插件 dataTables 是一个优秀的表格插件,提供了针对表格的排序.浏览器分页.服务器分页.筛选.格式化等功能.dataTables 的网站上也提供了大量 ...