CodeForces 845C Two TVs
2018-02-10 19:22
246 查看
题意:现在我们有一个电视清单,有两个电视,电视清单上有每一个节目的开始时间和结束时间。 电视不能接连不间断的播放,例如TV1播放完1-2点的节目后不能接着播放2-3点的电视,除非在TV2上播放,如果TV2也正在播放则不能播放完清单。Input
3 1 2 2 3 4 5Output
YESInput
4 1 2 2 3 2 3 1 2Output
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; }
相关文章推荐
- Codeforces - 845C Two TVs
- codeforces 845C Two TVs
- Codeforces 845C Two TVs【思维】水题
- 【CodeForces】870 F. Paths
- CodeForces 137A
- Codeforces 549F Yura and Developers
- CodeForces 246D. Colorful Graph【STL】
- codeforces 589J
- (最小生成树)Codeforces 76 A Gift
- Codeforces 620E New Year Tree dfs序+线段树+状态压缩
- CodeForces 599 D.Randomizer(计算几何+期望)
- codeforces 330A 330B 329A 分别是7月20DIV2的前三题
- Codeforces 551C GukiZ hates Boxes(二分)
- codeforces_667D. World Tour
- 【CodeForces 208B】Solitaire
- Codeforces 809D [平衡树][动态规划]
- Codeforces 873C Strange Game On Matrix【贪心】水题
- codeforces 908G - New Year and Original Order 数位dp
- CodeForces 154B——Colliders——筛选素数,模拟标记
- Codeforces 552E - Vanya and Brackets【表达式求值】