标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4037 | Accepted: 1845 |
Description
Input
Output
Sample Input
1 2 1 4 2 4 2 6 4 4 4 7 6 6 0 0 1 1 2 2 4 4 0 0 -1 -1
Sample Output
2 1
Source
1 #include <stdio.h> 2 #include <algorithm> 3 using namespace std ; 4 5 struct field 6 { 7 int h ; 8 int z ; 9 } ; 10 field num[600] ; 11 12 bool cmp(field h,field z) /* 13 { 14 if(h.h == z.h) 15 return h.z < z.z ; 16 else 17 return h.h < z.h ; /* 18 } 19 20 21 int main() 22 { 23 int m,n,i ; 24 while(~scanf("%d %d",&num[0].h, &num[0].z) , (num[0].h!=-1 , num[0].z!=-1)) 25 { 26 for(i=1; ;i++) 27 { 28 scanf("%d %d",&num[i].h, &num[i].z) ; 29 if(!num[i].h , !num[i].z) 30 break; 31 } 32 sort(num, num+i, cmp) ; 33 int temp, j, k, total=0 ; 34 for(j=0; j<i; j++) /*不可先遍历,后统计!0个数,不是最优 ; 35 { 36 if(num[j].z != 0) 37 { 38 temp = num[j].z ; 39 total++; 40 for(k=j+1; k<i; k++) 41 { 42 if(num[k].z >= temp) 43 { 44 temp=num[k].z ; 45 num[k].z = 0 ; 46 } 47 } 48 } 49 50 } /* 51 printf("%d\n",total); 52 } 53 return 0 ; 54 }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4623586.html