题目1434:今年暑假不AC

#include<iostream>
#include<algorithm>
using namespace std;
 
class MyTime{
public:
    int begin; //开始时间
    int end; //结束时间
    bool operator <(const MyTime &timeA)const //此处const丢了
    {
        return this->end < timeA.end;
    }
    bool canPlay(const MyTime &timeB);
};
bool MyTime::canPlay(const MyTime &timeB)
{
    if(this->end <= timeB.begin)
    {
        return true;
    }
    else
        return false;
}
 
 
MyTime times[100]; //记录每场节目起始点
 
int main()
{
    int n;//记录n中节目安排
 
    while(cin >> n && 0!=n)
    {
        for(int i=0; i<n; i++)
        {
            cin >> times[i].begin >> times[i].end;
        }
 
        sort(times,times+n);//对节目进行排序
        int cnt =1;//记录可以看的节目数
        for(int m=0,j=1; j<n;j++)
        {
            //此处犯二了,最开始用的是if(times[j].canPlay(times[j+1]))
            //也就是一直是前一个后一个,应该是拿已选择观看的节目来与下一个要看的比
            //cout << times[j].begin << " " << times[j].end << endl;
            if(times[m].canPlay(times[j]))
            {
            //  cout << times[j].begin << " " << times[j].end << endl;
                cnt ++;
                m= j;
            }
        //  else
        //  {
        //      cout << "Hello world" <<endl;
        //  }
             
        }
        cout << cnt <<endl;
    }
    return 0;
}
/**************************************************************
    Problem: 1434
    User: itswyy
    Language: C++
    Result: Accepted
    Time:10 ms
    Memory:1520 kb
****************************************************************/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值