用两个数组存储,再排序就OK了,如果有1 2,没有2 1,那么第二个数组排序后肯定没有1 2,那么就NO了~~~
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4
5 struct per
6 {
7 int start,end;
8 };
9 per p[500010],rp[500010];
10
11 bool cmp(per p1,per p2)
12 {
13 if(p1.start == p2.start)
14 return p1.end < p2.end;
15 else
16 return p1.start < p2.start;
17 }
18
19 int main()
20 {
21 int n;
22
23 while(scanf("%d",&n) == 1)
24 {
25 if(!n)
26 break;
27
28 int i;
29 for(i = 0;i < n;i ++)
30 {
31 int a,b;
32 scanf("%d%d",&a,&b);
33 p[i].start = a;
34 p[i].end = b;
35 rp[i].start = b;
36 rp[i].end = a;
37 }
38
39 std::sort(p,p + n,cmp);
40 std::sort(rp,rp + n,cmp);
41
42 int br = 1;
43 for(i = 0;i < n;i ++)
44 {
45 if(p[i].start != rp[i].start||p[i].end != rp[i].end)
46 {
47 br = 0;
48 break;
49 }
50 }
51 if(br)
52 printf("YES\n");
53 else
54 printf("NO\n");
55 }
56
57 return 0;
58 }