Uva:10763-foreign Exchange (sort)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.