首页 > 其他 > 详细

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

时间:2014-04-26 18:20:25      阅读:603      评论:0      收藏:0      [点我收藏+]

快排+贪心

bubuko.com,布布扣
 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\n",count);                      
45     }
46     return 0;  
47 }
bubuko.com,布布扣

 

HDU 2037 今年暑假不AC 快排+贪心,布布扣,bubuko.com

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

原文:http://www.cnblogs.com/lqquan/p/3691716.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!