cfC. Two TVs
来源:互联网 发布:ipad淘宝开店 编辑:程序博客网 时间:2024/05/04 04:45
C. Two TVs
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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?
Input
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.
Output
If Polycarp is able to check out all the shows using only two TVs then print “YES” (without quotes). Otherwise, print “NO” (without quotes).
Examples
input
3
1 2
2 3
4 5
output
YES
input
4
1 2
2 3
2 3
1 2
output
NO
本题就是要处理线段重合的问题,用一个数组排序后,加1减1操作判断是否该电视机在占用,
要注意同一时刻电视机结束放映并开始放映是不行的,也就是结束必须在等1个时间之后才能放。
涉及到离散化最后一个端点,最后一个端点必须+1.
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include<cstdio>#include<cstdlib>#include<cmath>#include <vector>using namespace std;vector<pair<int,int> >e;int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++){ int l,r; scanf("%d%d",&l,&r); e.push_back(make_pair(l,1)); e.push_back(make_pair(r+1,-1)); } int cnt=0; sort(e.begin(),e.end()); for(int i=0;i<e.size();i++){ cnt+=e[i].second; if(cnt>2) return 0*printf("NO"); } return 0*printf("YES");}
- cfC. Two TVs
- codeforces 845C Two TVs
- Codeforces 845 C Two TVs
- Codeforces 845C Two TVs【思维】水题
- CodeForces 845C Two TVs (模拟)
- Codeforces-845C:Two TVs(思维)
- Educational Codeforces Round 27 C. Two TVs(模拟)
- Codeforces 845 C. Two TVs 思路:简单贪心算法
- CFC Browser
- cfC. Pride
- 处理图片的CFC
- 【转载】CFC 心得
- TVS管
- TVS二极管
- TVS学习
- TVS二极管
- cfml 组件(cfc)示例源代码
- TVS二极管应用
- HYSBZ2038 小Z的袜子(莫队算法)
- JavaScript面试题大全
- 解决Android加载so库失败:java.lang.UnsatisfiedLinkError
- Tomcat8.5源码分析-StandardHost
- MySQL权限的详细解答
- cfC. Two TVs
- 数据标准化
- java--批量处理图片 非递归版
- 每天一个linux命令(7):mv命令
- mongodb命令总结+nodejs增删改查的封装
- CLion配置Boost
- windows下配置mysql主从备份
- 第十二篇:TCP的流量控制机制
- jstl各种日期处理