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. PHP读书笔记(5)-结构语句

    PHP结构语句 顺序结构 顺序结构就像一条直线,按着顺序一直往下执行.我们编写的代码默认都是按照顺序结构执行的. 条件结构之if…else… 条件结构就像一个岔路口,可以向左走,也可以向右走.比如上洗 ...

  2. 安卓Design包之Toolbar控件的使用

    转自:ToolBar的使用 ToolBar的出现是为了替换之前的ActionBar的各种不灵活使用方式,相反,ToolBar的使用变得非常灵活,因为它可以让我们自由往里面添加子控件.低版本要使用的话, ...

  3. SQL Server 日期 时间类型

    --1毫秒=0.001秒 --1微秒=0.000 001秒 --1纳秒=0.000 000 001秒 --datetime精度不大好,末尾值只能是这3种: .000, .003, or .007 -- ...

  4. html的标签中 unselectable=on 属性的作用

    在IE浏览器中,当input获得焦点时,点击有unselectable="on"属性的标签时,不会触发onblur事件. 加上该属性的元素不能被选中. < !DOCTYPE ...

  5. [改善Java代码]异常只为异常服务

    异常原本是正常逻辑的补充,但是有时候会被当做主逻辑使用.看如下代码: public class Client { enum Color { Red, Blue; } public static voi ...

  6. 关于解决form表单记录上次保存填写记录清空

    传进来的是一个HTML的Table的ID. function doReset(tableId){ var tbl_content = document.getElementById(tableId); ...

  7. 关于Eclipse插件之IWorkbench IWorkbenchWindow IWorkbenchPage |WorkbenchPart......等的总结

    1..IWorkbench: workbench是eclipse用户界面中最底层的对象,它建立在Display之上,包含一个或多个IWorkbenchWindow,用于向终端用户呈现信息 当你的wor ...

  8. https抓包判断证书问题

    openssl s_client -connect 61.135.250.130:443这个是reg.163.com的 tcpdump 也可

  9. Linux 命令 - cp: 拷贝文件和目录

    命令格式 cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t DIRECTORY ...

  10. Git CMD - checkout: Switch branches or restore working tree files

    命令格式 git checkout [-q] [-f] [-m] [<branch>] git checkout [-q] [-f] [-m] --detach [<branch&g ...