UVA 10763 (13.12.05)

Problem E
Foreign Exchange
Input:
standard input
Output: standard output
Time Limit: 1 second

Your non-profit organization (iCORE - internationalConfederation ofRevolver Enthusiasts) coordinates a very successful foreignstudent exchange program. Over the last few years, demand has sky-rocketed andnow you need assistance with your task.

The program your organization runs works asfollows: All candidates are asked for their original location and the locationthey would like to go to. The program works out only if every student has asuitable exchange partner. In other words, if a student wants to go from A toB, there must be another student who wants to go from B to A. This was an easytask when there were only about 50 candidates, however now there are up to500000 candidates!

Input

The input file contains multiplecases. Each test case will consist of a line containingn - the numberof candidates (1≤n≤500000), followed bynlines representing the exchange information for each candidate. Each of theselines will contain2 integers,separated by a single space, representing the candidate's original location andthe candidate's target location respectively. Locations will be represented bynonnegative integer numbers. You may assume that no candidate will have his orher original location being the same as his or her target location as thiswould fall into the domestic exchange program. The input is terminated by acase wheren = 0;this case should not be processed.

Output

For each testcase, print "YES" on asingle line if there is a way for the exchange program to work out, otherwiseprint"NO".

SampleInput                              Output for 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   YES NO

Problem setter: Gilbert Lee, University of Alberta,Canada

AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>

using namespace std;

int num1[555555];
int num2[555555];

int main() {
int n;
while(scanf("%d", &n) != EOF && n) {
for(int i = 0; i < n; i++)
scanf("%d %d", &num1[i], &num2[i]);
sort(num1, num1+n);
sort(num2, num2+n);

int mark = 1;
for(int i = 0; i < n; i++) {
if(num1[i] != num2[i]) {
mark = 0;
break;
}
}
if(mark)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

• 本文已收录于以下专栏：

uva 10763

UVA 10763 Foreign Exchange

• qian99
• 2014年01月12日 16:06
• 565

UVa 10763 - Foreign Exchange（结构体排序）

• wcr1996
• 2014年11月03日 18:15
• 1336

UVA 10763 Foreign Exchange 出国交换 pair+map

• hcbbt
• 2013年08月25日 21:13
• 1883

【UVa】10763 – Foreign Exchange

Problem hereProblemYour non-profit organization (iCORE – international Confederation of Revolver Ent...

uva 10763 Foreign Exchange

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

举报原因： 您举报文章：UVA 10763 (13.12.05) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)