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. oracle存储过程分页

    1.首先在oracle中建包体,用于游标返回当前数据记录集 CREATE OR REPLACE PACKAGE pkg_query AS TYPE cur_query IS REF CURSOR; E ...

  2. 探讨PHP页面跳转几种实现技巧

    PHP被许多程序员用来开发WEB的首选语言.在实际开发中,网站的各项功能都可以通过PHP语言的编写来满足,比如PHP页面跳转这一方法. 探讨PHP变量解析顺序如何获取提交数据 深入解读PHP运行机制 ...

  3. AngularJs学习经验汇集

    >>关于ng-include 有时候你会发现你用这个指令想要加载某个模板总是加载不出来,url明明是对的,页面还是一片空白,这里有一个细节要注意以下: <div ng-include ...

  4. CSS text-transform 属性——转换文本的大小写格式

    可能的值 值 描述 none 默认.定义带有小写字母和大写字母的标准的文本. capitalize 文本中的每个单词以大写字母开头. uppercase 定义仅有大写字母. lowercase 定义无 ...

  5. Flex性能优化常用手法总结 转

    转自:http://bbs.51aspx.com/showtopic-43693.html 随着Flex越来越多的被人们所熟知,越来越多的互联网也开始了RIA应用.众所周知,目前国内的宽带应用并不是像 ...

  6. 关于Linux测试题

    Linux 测试题: 1. 在Linux系统中,以 文件 方式访问设备 . 2. 某文件的权限为:drw-r--r--,用数值形式表示该权限,则该八进制数为: 644 ,该文件属性是 目录 . 3. ...

  7. linux下svn命令常用操作

    1.将文件checkout到本地目录 svn checkout path(path是服务器上的目录) 例如:svn checkout svn://192.168.1.1/pro/domain 简写:s ...

  8. Networking - ARP 协议

    ARP 协议概述 ARP(Address Resolution Protocol),即地址解析协议,用于把 IP 地址映射到物理地址.网段上的每台主机都维护着一个被称为 ARP Table 或 ARP ...

  9. 在Delphi中,关于数组名称

    动态数组数组名代表的是第一个元素的内存地址. 静态数组名称代表的是数组第一个元素的内存位置, 而不是数组第一个元素的内存地址. 但对于静态数组,在某些情况下编译器可能会自动取数组地址,如: funct ...

  10. 需要MARK一下,奇怪的ANDROID SDK自带的APK加密功能的问题

    花了两天时间,各种调试APP,发现问题不在于代码. 在于用了SDK里的加密,导致运行其中一个多线程中的ACTIVITY, 就会黑屏,返回按钮也没用. 发现这个问题的思路是因为,我发现连手机直接调试,一 ...