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 ".