http://acm.hdu.edu.cn/showproblem.php?pid=2037
/*
该题难在,想到,如何看尽可能多的完整节目的方案。如何找到最佳方案的步骤。程序也就是代码并不难。
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXSIZE=100;
struct Show{
int begin;
int over;
};
bool Compare(Show x,Show y){
if(x.over==y.over){
return x.begin<y.begin;
}else{
return x.over<y.over;
}
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
if(n==0){
break;
}
Show show[MAXSIZE];
for(int i=0;i<n;++i){
scanf("%d %d",&show[i].begin,&show[i].over);
}
sort(show,show+n,Compare);
int temp;//这里用一个整型就行,不用搞得那么复杂
int k=1;
temp = show[0].over;
for(int i=1;i<n;++i){
if(show[i].begin>=temp){
temp=show[i].over;
++k;
}
}
printf("%d\n",k);
// scanf("%d",&n);//这不对
}
}
/*
0_0_35464019_15079.cpp
0_0_35464019_15079.cpp(29) : error C2057: 应输入常量表达式
0_0_35464019_15079.cpp(29) : error C2466: 不能分配常量大小为 0 的数组
0_0_35464019_15079.cpp(29) : error C2133: “show”: 未知的大小
*/

京公网安备 11010502036488号