先對出發地排序一次,再對目的地排序一次,兩兩比較是否一樣即可。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <algorithm> | |
using namespace std; | |
int N; | |
int origin[500001], target[500001]; | |
int main() | |
{ | |
while (scanf("%d",&N)){ | |
if (!N) break; | |
for (int i=0; i<N; i++) | |
scanf("%d %d",&origin[i],&target[i]); | |
if (N % 2) { | |
printf("NO\n"); | |
continue; | |
} | |
sort(origin, origin+N, cmp); | |
sort(target, target+N, cmp); | |
bool yes = 1; | |
for (int i=0; i<N; i++) | |
if (origin[i] != target[i]) | |
yes = 0; | |
printf("%s\n", yes ? "YES" : "NO"); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言