赞
踩
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).
3 1 2 2 3 4 5
YES
4 1 2 2 3 2 3 1 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;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。