HDU 2037 今年暑假不AC 快排+贪心

快排+贪心

 1 #include<stdio.h>
 2 int a[110],b[110];
 3 void quicksort(int a[],int low,int high)
 4 {
 5     int i=low;
 6     int j=high;
 7     int temp=a[i];
 8     int temp2=b[i]; 
 9     if(i<j)
10     {
11         while(i<j)
12         {
13             while(a[j]>=temp&&i<j) j--;                             
14             a[i]=a[j];
15             b[i]=b[j];
16             while(a[i]<=temp&&i<j) i++;
17             a[j]=a[i];
18             b[j]=b[i];
19         } 
20         a[i]=temp;
21         b[i]=temp2;
22         quicksort(a,low,i-1);
23         quicksort(a,j+1,high);
24     }
25     else return;   
26 }
27 int main(void)
28 {
29     int n;
30     int start,count;
31     while(scanf("%d",&n)&&n)
32     {  
33         for(int i=0;i<n;i++)
34             scanf("%d %d",&b[i],&a[i]);
35         quicksort(a,0,n-1);  
36         start=a[0];
37         count=1;
38         for(int i=1;i<n;i++)
39             if(b[i]>=start) 
40             {
41                 start=a[i];     
42                 count++;
43             }   
44         printf("%d
",count);                      
45     }
46     return 0;  
47 }
原文地址:https://www.cnblogs.com/lqquan/p/3691716.html