hdu2037贪心

题目:hdu2037

Input
输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(n<=100),表示你喜欢看的节目的总数,然后是n行数据,每行包括两个数据Ti_s,Ti_e (1<=i<=n),分别表示第i个节目的开始和结束时间,为了简化问题,每个时间都用一个正整数表示。n=0表示输入结束,不做处理。
 

Output
对于每个测试实例,输出能完整看到的电视节目的个数,每个测试实例的输出占一行。
 

Sample Input

12 1 3 3 4 0 7 3 8 15 19 15 20 10 15 8 18 6 12 5 10 4 14 2 9 0
 

Sample Output

5
 

不可能从一个节目的开始时间来考虑。要考虑的是结束时间。第一个节目一定是结束时间最早的那个节目,依次类推,下一个节目是前一个节目以后开始而且第一个结束的节目。

#include 
#include 
#include 
using namespace std;
struct pro
{
    int pros;
    int proe;
};
bool cmp(pro a,pro b)
{
    return a.proe < b.proe;
}
int main()
{
    int n,cnt,time;
    pro p[105];
    while(scanf("%d",&n) && n)
    {
        cnt=0;
        time=0;//排序后的第一个节目必然作为目标结果的第一个节目
        for(int i=0;i=time)//后一个节目在前一个节目结束之后开始
            {
                cnt++;
                time=p[i].proe;//更新现在的时间
            }
        }
        printf("%d\n",cnt);
    }
}


你可能感兴趣的:(ACM)