Problem E

题意:看电视,计算出最多看多少个电视,已给出电视起始终止时间;
解体思路:思路这个题拿到手没多想,上课的例题,就照葫芦画瓢写了一个;
感悟:虽然刚开始学贪心,第一遍代码就AC了有点小小的成就感;
代码(G++ 0MS)
#include
#include
#include
using namespace std;
struct Ti{
    int s;
    int e;
    bool operator < (const Ti& other) const
    {
        if(this->e==other.e)
            this->s
        return this->e
    }
};
int main()
{
    //freopen("in.txt", "r", stdin);
    int n,s,e,ans=1,d=1;
    Ti t1[101],t2[101];
    while(~scanf("%d",&n)&&n)
    {
        ans=1;
        d=1;
        for(int i=0;i
        {
            scanf("%d%d",&s,&e);
            t1[i].s=s;
            t1[i].e=e;
        }
        stable_sort(&t1[0],&t1[n]);//按照节目时间由短到长排列
        t2[0]=t1[0];//因为第一个是必须看的;
        //cout<<"t1[0].s="<<t1[0].s<<" "<<"t1[0].e="<<t1[0].e<<endl;
        for(int i=1;i
        {
            if(t1[i].s>=t2[d-1].e)
            {
                //cout<<"t2[d-1].s="<<t2[d-1].s<<" "<<"t2[d-1].e="<<t2[d-1].e<<endl;
                t2[d++]=t1[i];
                ans++;
            }
          

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/5781678.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值