Title: 10763-foreign Exchange
The main topic: give each classmate want to exchange coordinates A, b for this classmate in position a want to and B position classmate Exchange. Ask every student to find an exchange student who is exchanging with him.
The problem-solving idea: The given sequence of the original given, after the exchange of the position and then get a new sequence.
Assume that the new sequence and the original sequence also meet the requirements. Since (A. b) (b. A) if the pair appears. Then after the exchange is still (b. A) (A. b).
Code:
#include <stdio.h> #include <string.h> #include <algorithm>using namespace std;const int N = 500005;int N;STRUCT candidates {int x, y;} Candidates[n], Temp[n];bool CMP (const candidates &C1, const candidates &C2) {if (c1.x = = c2.x) return C1.Y < C2 . Y;return c1.x < c2.x;} BOOL Judge () {for (int i = 0; i < n; i++) if (candidates[i].y! = temp[i].y | | temp[i].x! = candidates[i].x) return False;return true;} int main () {int x, y;while (scanf ("%d", &n), N) {for (int i = 0; i < n; i++) {scanf ("%d%d", &x, &y); cand idates[i].x = X;candidates[i].y = y;temp[i].x = Y;temp[i].y = x;} if (n% 2) { //here to note. Cannot write to the front of the input data. Because of this many times tlprintf ("no\n"); continue;} Sort (Temp, temp + N, CMP), sort (candidates, candidates + N, CMP);p rintf ("%s\n", Judge ()? "YES": "NO");} return 0;}
Uva:10763-foreign Exchange (sort)