# UVA 10763 (13.12.05)

503人阅读 评论(0)

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;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：90977次
• 积分：2372
• 等级：
• 排名：第15734名
• 原创：152篇
• 转载：0篇
• 译文：0篇
• 评论：11条
博客专栏
 ACM专栏 文章：1篇 阅读：705
阅读排行
评论排行
最新评论