Description
Input
Output
Sample Input
Sample Output
1 #include<iostream> 2 #include<cmath> 3 #include<algorithm> 4 using namespace std; 5 6 struct point 7 { 8 int s; 9 int e; 10 }; 11 12 point a[101]; 13 14 int time(point m) 15 { 16 return m.e-m.s; 17 } 18 19 int cmp(point a,point b) 20 { 21 return a.e<b.e; 22 } 23 24 25 int main() 26 { 27 int n; 28 while(cin>>n) 29 { 30 if(n==0) 31 break; 32 for(int i = 0;i<n;i++) 33 cin>>a[i].s>>a[i].e; 34 35 sort(a,a+n,cmp); 36 //index保存索引而不是数据好一些 37 int count = 1,index = 0; 38 for(int i = 1;i<n;i++) 39 { 40 if(a[index].e<=a[i].s) 41 { 42 count++; 43 index = i; 44 } 45 } 46 cout<<count<<endl; 47 } 48 49 }
原文:http://www.cnblogs.com/qlky/p/4958320.html