Ultraviolet A 10763-Foreign Exchange

Source: Internet
Author: User

The two series are sorted and compared. If they are identical, "yes" is output; otherwise, "no" is output ".

CodeAs follows:

# Include <iostream> # include <cstring> # include <cstdlib> # include <cstdio> # include <cmath> # include <string> using namespace STD; int n_cmp (const void * a, const void * B) {return * (int *) A-* (int *) B;} int A [500000 + 2], B [500000 + 2]; int main () {# ifdef test freopen ("sample.txt", "r", stdin); # endif int num; while (scanf ("% d", & num )! = EOF) {If (! Num) break; For (INT I = 0; I <num; I ++) scanf ("% d", & A [I], & B [I]); qsort (A, num, sizeof (A [0]), n_cmp); qsort (B, num, sizeof (B [0]), n_cmp); int flag = 0; For (INT I = 0; I <num; I ++) if (a [I]! = B [I]) {flag = 1; break;} If (flag = 0) cout <"yes" <Endl; else cout <"no" <Endl;} return 0 ;}

Although the above method can be AC, there are bugs (if there are three people: [10 30], [30, 20], [20, 10]). Thank you. E_s_promise pointed out the error. At that time, I did take it for granted too much, and the data of this question was indeed watered down.

The correct method should be structured storage, followed by sorting + binary search and pairing. "Yes" can be output until all pairs are paired successfully. Otherwise, "no" can be output ".

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.