今年暑假不AC
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2037
1 #include<stdio.h> 2 //快速排序 3 void sort(int *a,int *b,int i,int j) 4 { 5 int x=i,y=j,key=a[i],ke=b[i]; 6 if(x>=y)return ; 7 while(x!=y) 8 { 9 while(x<y&&a[y]>=key)y--; 10 a[x]=a[y],b[x]=b[y]; 11 while(x<y&&a[x]<=key)x++; 12 a[y]=a[x],b[y]=b[x]; 13 } 14 a[x]=key;b[x]=ke; 15 sort(a,b,i,x-1); 16 sort(a,b,x+1,j); 17 } 18 int main() 19 { 20 int n; 21 while(~scanf("%d",&n)&&n) 22 { 23 int i,a[110],b[110]; 24 for(i=0;i<n;i++) 25 scanf("%d%d",&a[i],&b[i]); 26 27 sort(a,b,0,n-1); 28 29 for(i=0;i<n-1;i++) 30 if(a[i]==a[i+1]) 31 if(b[i]>b[i+1]){int t=b[i];b[i]=b[i+1];b[i+1]=t;} 32 33 int count=1;int key=a[0],ke=b[0]; 34 for(i=1;i<n;i++){ 35 if(a[i]<ke&&b[i]<ke){key=a[i];ke=b[i];} 36 else if(a[i]>=ke){count++;key=a[i],ke=b[i];} 37 } 38 39 printf("%d\n",count); 40 } 41 return 0; 42 }