您的位置:首页 > 其它

CodeForces 845C Two TVs

2018-02-10 19:22 246 查看
题意:现在我们有一个电视清单,有两个电视,电视清单上有每一个节目的开始时间和结束时间。   电视不能接连不间断的播放,例如TV1播放完1-2点的节目后不能接着播放2-3点的电视,除非在TV2上播放,如果TV2也正在播放则不能播放完清单。Input
3
1 2
2 3
4 5
Output
YES
Input
4
1 2
2 3
2 3
1 2
Output
NO

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
struct node
{
int start;
int End;
}a[200005];
bool cmp(node a,node b)
{
if(a.start==b.start)
return a.End<b.End;
return a.start<b.start;
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;++i)
scanf("%d%d",&a[i].start
4000
,&a[i].End);
sort(a,a+n,cmp);
queue<node>x,y;
node q;
for(int i=0;i<n;++i)
{
if(x.empty())
x.push(a[i]);
else if(y.empty())
y.push(a[i]);
else if(!x.empty())
{
q=x.front();
if(a[i].start>q.End)
{
x.pop();
x.push(a[i]);
}
else if(!y.empty())
{
q=y.front();
if(a[i].start>q.End)
{
y.pop();
y.push(a[i]);
}
else
{
cout<<"NO"<<endl;
return 0;
}
}
}

}
cout<<"YES"<<endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: