CF1029C Maximal Intersection
https://www.luogu.org/problem/show?pid=CF1029C
#include<bits/stdc++.h>
using namespace std ;
#define LL long long LL read(){
char c ;
int sign = ;
while((c = getchar()) > '' || c < '')
if(c == '-') sign = - ;
LL ans = c - '' ;
while((c = getchar()) <='' && c >= '')
ans = ans * + c - '' ;
return ans * sign ;
} int n ;
LL l[] , r[] ;
LL la = , ra = 10e9 + ; void answer(){
la = , ra = 10e9 + ;
for(int i = ; i <= n ; ++ i){
la = max(la , l[i]) ;
ra = min(ra , r[i]) ;
}
} int main(){
n = read() ;
LL ansl = , ansr = ;
r[] = 10e9 + ;
l[] = ;
for(int i = ; i <= n ; ++ i){
l[i] = read() , r[i] = read() ;
}
answer() ;
if(la > ra) {
printf("%d",);
return ;
}
for(int i = ; i <= n ; ++ i){
if(l[i] == la){
if(r[i] < r[ansl]) {
ansl = i ;
}
}
if(r[i] == ra){
if(l[i] > l[ansr]){
ansr = i ;
}
}
}
if(ansr == ansl){
l[ansr] = ;
r[ansr] = 10e9 + ;
answer() ;
printf("%ld",ra - la) ;
return ;
}
else {
LL ii = l[ansr] ;
LL ff = r[ansr] ;
l[ansr] = , r[ansr] = 10e9 + ;
answer() ;
LL len = ra - la ;
l[ansr] = ii , r[ansr] = ff ;
l[ansl] = , r[ansl] = 10e9 + ;
answer() ;
len = max(len , ra - la) ;
printf("%ld",len) ;
return ;
}
}
CF1029C Maximal Intersection的更多相关文章
- CF1029C Maximal Intersection 暴力枚举
Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #506 (Div. 3) C. Maximal Intersection
C. Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
- Codeforces | CF1029C 【Maximal Intersection】
论Div3出这样巨水的送分题竟然还没多少人AC(虽说当时我也没A...其实我A了D...逃) 这个题其实一点都不麻烦,排序都可以免掉(如果用\(priority \_ queue\)的话) 先考虑不删 ...
- CodeForces C. Maximal Intersection
http://codeforces.com/contest/1029/problem/C You are given nn segments on a number line; each endpoi ...
- F - Maximal Intersection --------暴力求解题
You are given n segments on a number line; each endpoint of every segment has integer coordinates. S ...
- C. Maximal Intersection(STL)
这道题,关键在于怎么求多个区间的交集,使用multiset就可以 分别将 r , l 存在不同的mutiset中. 然后,我们来看一下 是不是 交集的 l 是最大的, 交集的 r 是最小的 #incl ...
- CF C. Maximal Intersection(贪心 || STL)
题意 给你N个线段(一条直线上),问删去一个之后,最长公共长度 : 分析:首先我们得先知道n条线段公共的线段一定是(LMAX,RMIN) ,那我们可以先排序,然后枚举删除边: #include< ...
- Codeforces Round #506 (Div. 3) 题解
Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...
- cf 1029 C
C. Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- eclipse查看jar包源文件
话不多说上链接 https://www.cnblogs.com/1995hxt/p/5252098.html这里介绍了完整的流程,亲自试过,可以的! 以防以后要用的时候找不到文件的下载地址,所以就先在 ...
- zuul的本地跳转
- 记录:swift学习笔记1-2
swift还在不断的更新做细微的调整,都说早起的鸟儿有虫吃,那么我们早点出发吧,趁着国内绝大多数的coder们还没有开始大范围普遍应用. 网上有些大神说:swift很简单!我不同意这个观点,假如你用h ...
- 洛谷 P1690 贪婪的Copy
题目 本题难度较低,操作比较简单,首先对于范围较小的N(<=100),我们可以先跑一遍floyd,求出任意两点之间的最短路.对于很小的p(<=15),我们可以直接考虑全排列,运用到next ...
- ae(ArcEngine) java swing开发入门系列(1):开发环境和代码部署
前言:做ae开发大部分人都是用C#版,很少用到java版,本系列文章主要介绍java版ae开发的入门,对于ae接口的高级应用,可以看C#版相关文章 开发环境软件: Intellij IDEA 2018 ...
- 获取元素Bytagname区别/for循环应用
一:两种获取元素方式的区别.1.var aLi = oUl.getElementsByTagName('li');TagName前面可以加其他东西,id就只能是document,2,Id是静态的,ta ...
- JSON 序列化格式
一.C#处理简单json数据json数据: 复制代码代码如下: {"result":"0","res_info":"ok" ...
- BZOJ 3712: [PA2014]Fiolki 倍增+想法
3712: [PA2014]Fiolki Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 437 Solved: 115[Submit][Status ...
- 协议详解3——IP
1. 特点: 所有的TCP,UDP,ICMP,IGMP数据都以IP数据报格式传输. 提供不可靠,无连接服务. 不可靠: 不能保证IP数据报能成功到达目的.IP仅提供最好的传输服务.如果发生某种错误时 ...
- 【转】iOS开发里的Bundle是个啥玩意?!
初学iOS开发的同学,不管是自己写的,还是粘贴的代码,或多或少都写过下面的代码 [[NSBundle mainBundle] pathForResource:@"someFileName&q ...