#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
****************************************************************/
题目1434:今年暑假不AC
最新推荐文章于 2020-03-23 11:36:27 发布