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 ...
随机推荐
- shell脚本杀死某个服务的进程
摘抄如下: 新建sh结尾的文件内容如下: NAME=$1echo $NAMEID=`ps -ef | grep "$NAME" | grep -v "$0" | ...
- 线段树合并(【POI2011】ROT-Tree Rotations)
线段树合并([POI2011]ROT-Tree Rotations) 题意 现在有一棵二叉树,所有非叶子节点都有两个孩子.在每个叶子节点上有一个权值(有nn个叶子节点,满足这些权值为1-n1-n的一个 ...
- BZOJ 2150 部落战争 (二分图匹配)
题目大意:给你一个n*m的棋盘,有一些坏点不能走,你有很多军队,每支军队可以像象棋里的马一样移动,不过马是1*2移动的,而军队是r*c移动的,军队只能从上往下移动,如果一个点已经被一直军队经过,那么其 ...
- Laravel源码解析之从入口开始
前言 提升能力的方法并非使用更多工具,而是解刨自己所使用的工具.今天我们从Laravel启动的第一步开始讲起. 入口文件 laravel是单入口框架,所有请求必将经过index.php define( ...
- MyEclipse报错Access restriction: The type BASE64Encoder is not accessible due to restriction on required library
错误截图: 解决办法: 1.进入Project --> Properties --> Java Build Path --> Libraries 2.remove 掉 JRE Sys ...
- (转载)使用Maven构建多模块项目
原文:https://www.cnblogs.com/xdp-gacl/p/4242221.html#undefined 在平时的Javaweb项目开发中为了便于后期的维护,我们一般会进行分层开发,最 ...
- 6.between...and...
6.在WHERE中使用between...and... 用于区间值的条件判断(包含边界值) //查询工资在2000(包含)到3000(包含)之间的员工信息 select empno,e ...
- Java採用JNI调用VC++生成的dll(Java与C++交互)
应项目需求,须要android调用java,java再调用C++实现android一个图片匹配的功能,我们作为java组须要和C++和Android进行交互.以下是java和C++採用JNI的方式进行 ...
- JDBC连接mysql时出现的ssl问题
使用MySQL数据库时出现如下错误: WARN: Establishing SSL connection without server's identity verification is not r ...
- 百度地图----->地图类型、定位模式、实时交通、我的位置、加入覆盖物、覆盖物详情及提示
在百度地图开发平台 http://developer.baidu.com/map/index.php? title=androidsdk 进行创建应用,获取应用的AK,在进行下载BaiduLBS_An ...