标签:
3
6 3
1 3
2 5
2
1 3
3 6
1 #include <iostream> 2 #include <algorithm> 3 4 using namespace std; 5 6 struct xian 7 { 8 int x,y; 9 }; 10 11 xian a[111]; 12 int n; 13 int cmp(xian a,xian b) 14 { 15 return a.y<b.y; 16 } 17 18 int main() 19 { 20 int x,y; 21 while(cin>>n) 22 { 23 for(int i=0;i<n;i++) 24 { 25 cin>>x>>y; 26 if(x>y) 27 swap(x,y); 28 a[i].x=x; 29 a[i].y=y; 30 } 31 sort(a,a+n,cmp); 32 int t=0,tem=0; 33 for(int i=0;i<n;i++) 34 { 35 if(a[i].x>=tem) 36 { 37 t++; 38 tem=a[i].y; 39 } 40 else 41 a[i].x=-1; 42 } 43 cout<<t<<endl; 44 for(int i=0;i<n;i++) 45 { 46 if(a[i].x!=-1) 47 cout<<a[i].x<<" "<<a[i].y<<endl; 48 } 49 } 50 return 0; 51 }
标签:
原文地址:http://www.cnblogs.com/asuml/p/5692170.html