UVA Foreign Exchange
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
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".
解题:直接模拟交换好了,如果最后还与交换之前一样,则YES
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
int d[maxn],n,u,v;
int main() {
while(scanf("%d",&n),n) {
for(int i = ; i <= n; ++i) d[i] = i;
for(int i = ; i < n; ++i) {
scanf("%d%d",&u,&v);
swap(d[u],d[v]);
}
bool flag = true;
for(int i = ; i <= n; ++i)
if(d[i] != i) {
flag = false;
break;
}
puts(flag?"YES":"NO");
}
return ;
}
UVA Foreign Exchange的更多相关文章
- UVA 10763 Foreign Exchange 出国交换 pair+map
题意:给出很多对数字,看看每一对(a,b)能不能找到对应的(b,a). 放在贪心这其实有点像检索. 用stl做,map+pair. 记录每一对出现的次数,然后遍历看看对应的那一对出现的次数有没有和自己 ...
- 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(排序)
题目:10763 - Foreign Exchange 题目大意:给出每一个同学想要的交换坐标 a, b 代表这位同学在位置a希望能和b位置的同学交换.要求每一位同学都能找到和他交换的交换生. 解题思 ...
- Foreign Exchange
10763 Foreign ExchangeYour non-profit organization (iCORE - international Confederation of Revolver ...
- Foreign Exchange(交换生换位置)
Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enth ...
- [刷题]算法竞赛入门经典(第2版) 5-4/UVa10763 - Foreign Exchange
题意:有若干交换生.若干学校,有人希望从A校到B校,有的想从B到C.C到A等等等等.如果有人想从A到B也刚好有人想从B到A,那么可以交换(不允许一对多.多对一).看作后如果有人找不到人交换,那么整个交 ...
- 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 ...
随机推荐
- [NOIP补坑计划]NOIP2015 题解&做题心得
感觉从15年开始noip就变难了?(虽然自己都做出来了……) 场上预计得分:100+100+60~100+100+100+100=560~600(省一分数线365) 题解: D1T1 神奇的幻方 题面 ...
- java实现随机数的生成
一,课程中的动手动脑的问题 1,编写一个方法,使用以上算法生成指定数目的随机整数. public void suiJiShu(){ Scanner input=new Scanner(System.i ...
- Tire树总结(模板+例题)
题目来自<算法竞赛设计指南> Tire树是一种可以快速查找字符串的数据结构 模板 #include<cstdio> #include<algorithm> #inc ...
- CSDN开博一周年--总结、感想和未来规划
2012年9月22日,我在CSDN发表了第1篇博文-为了忘却的纪念,我的天龙游戏生涯.本文讲述了我大学期间玩网络游戏-天龙八部的故事. 在大学期间,实际上我也有自己的帐号-huoyingfans,主要 ...
- WinServer-IIS-IIS负载均衡
安装应用程序路由 提供的服务器的地址必须是可以访问,不然无法进入到下面的这个管理界面 来自为知笔记(Wiz)
- C#一个托付的样例
C#中的函数能够被声明的一个托付所调用. 函数为静态方法.和托付声明的參数返回值要一致. class Program { delegate float MathOperationDelegate( ...
- poj2492--A Bug's Life(并查集变形)
A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 28703 Accepted: 9350 De ...
- Tesseract 3.04 + VS2013 配置心得(包括静态库版本号和Release版本号)
研究Tesseract也有几个星期了 走了一些弯路 网上有非常多VS2010的配置心得 但没有VS2013的, 找到一篇之后, 又发现会有一些小问题, 这里记录下来, 也为新人提供一些帮助. Tess ...
- Android简单实现BroadCastReceiver广播机制
Android中广播的作用是很明显的,当我们收到一条信息,可能我们的应用须要处理一些数据.可能我们开机.我们的应用也须要处理一些数据,这里都用到了广播机制,这里简单的实现了一个自己定义广播.看实例: ...
- MLPclassifier,MLP 多层感知器的的缩写(Multi-layer Perceptron)
先看代码(sklearn的示例代码): from sklearn.neural_network import MLPClassifier X = [[0., 0.], [1., 1.]] y = [0 ...