Educational Codeforces Round 27 C. Two TVs(模拟)
来源:互联网 发布:兄弟连it教育论坛 编辑:程序博客网 时间:2024/05/18 08:01
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment li and ends at moment ri.
Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV.
Polycarp wants to check out all n shows. Are two TVs enough to do so?
The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of shows.
Each of the next n lines contains two integers li and ri (0 ≤ li < ri ≤ 109) — starting and ending time of i-th show.
If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).
31 22 34 5
YES
41 22 32 31 2
NO
题解:
题意:
有两台电视,有节目的开始时间和结束时间,这题的题意还蛮有意思,你可以同时看两个节目,但是你在一个节目结束的时刻不能用这一台开下一个这个时刻开始的节目(但是可以换一台看),问你是否可以看完所有节目,直接模拟两个电视的关闭情况就行了
代码:
#include<algorithm>#include<iostream>#include<cstring>#include<stdio.h>#include<math.h>#include<string>#include<stdio.h>#include<queue>#include<stack>#include<map>#include<vector>#include<deque>using namespace std;#define lson k*2#define rson k*2+1#define M (t[k].l+t[k].r)/2#define INF 1008611111#define ll long long#define eps 1e-15struct node{ int s,t; int d;}a[200005];int cmp(node x,node y)//节目开始时间从小到大排,相同结束时间早的在前{ if(x.s!=y.s) return x.s<y.s; return x.t<y.t;}struct tv{ int e;//记录电视节目的结束时间 int tag;//记录电视的开闭}t[5];int main(){ int i,j,n,flag=1; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d%d",&a[i].s,&a[i].t); } sort(a,a+n,cmp); t[0].e=-1; t[1].e=-1; t[0].tag=0; t[1].tag=0; for(i=0;i<n;i++)//模拟电视的开闭 { if(a[i].s>t[0].e)//根据节目的结束时间清除电视的状态 { t[0].tag=0; } if(a[i].s>t[1].e) { t[1].tag=0; } if(!t[0].tag)//如果第一台可以看 { t[0].tag=1; t[0].e=a[i].t; } else if(!t[1].tag) { t[1].tag=1; t[1].e=a[i].t; } else { flag=0; break; } } if(flag) printf("YES\n"); else printf("NO\n"); return 0;}
- Educational Codeforces Round 27 C. Two TVs(模拟)
- CodeForces 845C Two TVs (模拟)
- Codeforces - Educational Codeforces Round 14C - Exponential notation(模拟)
- Educational Codeforces Round 17 C. Two strings(二分)
- Educational Codeforces Round 11 C (Two Pointers)
- Educational Codeforces Round 17-C Two strings
- Educational Codeforces Round 26 C. Two Seals
- Educational Codeforces Round 26 C. Two Seals
- Educational Codeforces Round 26 C. Two Seals
- Educational Codeforces Round 26:C. Two Seals
- Educational Codeforces Round 32 C. K-Dominant Character(模拟)
- codeforces 845C Two TVs
- Codeforces 845 C Two TVs
- Educational Codeforces Round 17 C && codeforces 762C C. Two strings(前缀后缀的妙用)
- Educational Codeforces Round 6 (B)模拟
- Educational Codeforces Round 7(B)模拟
- Educational Codeforces Round 10(A)模拟
- Educational Codeforces Round 11(B)模拟
- dubbo-admin-2.5.3.war管控台运行jdk1.8报错Invalid property 'URIType' of bean class
- 识别MNIST数据集:用Python实现神经网络
- jstl 自定义标签来写IO流数据
- Linux 如何添加一个 Swap 文件
- 常用排序算法总结(二)
- Educational Codeforces Round 27 C. Two TVs(模拟)
- 文章为原创,转载请注明出处,欢迎评论。
- 第一行代码 第九章 网络技术
- 数据库简单介绍
- 跳动的心
- [51Nod 1110 距离之和最小 V3]三分
- 浅谈Java中的equals和==
- OpenCV入门笔记
- POJ 1222 EXTENDED LIGHTS OUT【暴力dfs】