codeforces 845C Two TVs
来源:互联网 发布:9008端口刷机工具 编辑:程序博客网 时间:2024/05/12 01:00
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
题意:给两个电视机,一个节目的开始时间和一个节目的结束时间相同,则这两个节目只能在不同电视机上,问给定节目能否看完
对开始时间进行排序,再模拟一下就好
#pragma comment(linker,"/STACK:1024000000,1024000000")#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<stack>#include<queue>#include<deque>#include<set>#include<map>#include<cmath>#include<vector>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> PII;#define pi acos(-1.0)#define eps 1e-10#define pf printf#define sf scanf#define lson rt<<1,l,m#define rson rt<<1|1,m+1,r#define e tree[rt]#define _s second#define _f first#define all(x) (x).begin,(x).end#define mem(i,a) memset(i,a,sizeof i)#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)#define mi ((l+r)>>1)#define sqr(x) ((x)*(x))const int inf=0x3f3f3f3f;const int Max=2e5+1;int L,l,R,r,n;struct node{ int x,y;}t[Max];bool cmp(const node& a,const node& b){ return a.x<b.x;}int main(){ while(~sf("%d",&n)) { L=R=l=r=-1;//初始化,两个电视均无播出节目 int tag=1; for1(i,n) sf("%d%d",&t[i].x,&t[i].y); sort(t+1,t+n+1,cmp); for1(i,n) { if(L==-1||t[i].x>R)//第一个电视无节目或播出时间在结束之后(不能相等) L=t[i].x,R=t[i].y; else { if(l==-1||t[i].x>r) l=t[i].x,r=t[i].y; else tag=0; } } puts(tag?"YES":"NO"); } return 0;}
- codeforces 845C Two TVs
- Codeforces 845 C Two TVs
- Codeforces 845C Two TVs【思维】水题
- CodeForces 845C Two TVs (模拟)
- Codeforces-845C:Two TVs(思维)
- Codeforces 845 C. Two TVs 思路:简单贪心算法
- Educational Codeforces Round 27 C. Two TVs(模拟)
- cfC. Two TVs
- CodeForces 762C Two strings
- 【Codeforces 837C. Two Seals】
- CodeForces 425C Sereja and Two Sequences
- Educational Codeforces Round 11 C (Two Pointers)
- 【50.00%】【codeforces 602C】The Two Routes
- [codeforces] 762C - Two strings 线段树
- 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
- as中日志工具Log
- Java——I/O操作之拷贝文件
- javascript 中,function 方法前面一个分号是啥意思
- struts2面试题
- HDU题目分类
- codeforces 845C Two TVs
- hdu 1401 Solitaire(双向宽搜)
- springmvc 文件上传与下载
- windows10下cuda8.0+cudnn6.0+PYthon3.5.3+tensorflow安装
- 关于post数据服务器端接收不全
- 新路程------hi3516a在menuconfig加ko编译
- TOPGP5.3:p_link增加编译、链接功能
- 定位中获取地址位置的两种方式
- vi命令模式下的一些技巧