【解题报告】【HDOJ2037】【贪心算法】今年暑假不AC
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2037
1 #include<stdio.h> 2 struct node{ 3 int x,y; 4 }; 5 int main() 6 { 7 struct node a[101]; 8 int i,j,n,sum,q,y,w,t; 9 //freopen("1.txt","r",stdin); 10 while(scanf("%d",&n)!=EOF&&n) 11 { 12 for(i=0;i<n;i++) scanf("%d%d",&a[i].x,&a[i].y); 13 for(i=0;i<n;i++) 14 { 15 for(j=i;j<n;j++) 16 { 17 if(a[i].y>a[j].y) 18 { 19 t=a[i].x; 20 a[i].x=a[j].x; 21 a[j].x=t; 22 t=a[i].y; 23 a[i].y=a[j].y; 24 a[j].y=t; 25 } 26 } 27 } 28 29 q=0;w=a[0].y; 30 sum=1; 31 for(i=1;i<n;i++) 32 { 33 if(a[i].x>=w) 34 { 35 w=a[i].y; 36 sum++; 37 } 38 } 39 printf("%d\n",sum); 40 } 41 return 0; 42 }