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 ...
随机推荐
- leecode-39. Combination Sum
1.问题描述: Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all ...
- 打war包时无法把src/main/java里的xml文件打包上去
maven打包默认打src/mian/resource里面的xml,而不会去src/main/java,所以 再pom.xml里的bulid节点里加上 <resources> <re ...
- golang学习资料
http://yougg.github.io/static/gonote/GolangStudy.html
- [Java][Web] Servlet中转发和重定向比较
Servlet中页面跳转的两种方式 请求转发 使用requestDispatcher对象 request.getRequestDispatcher("path").forward( ...
- new() 与new
一般写的时候,new对象都要加()
- .net core 的跨域
.net core 的跨域问题花了 我很长时间 接下来我简单的描述下解决过程 首先我在前端用jquery的ajax去调用自己的本地接口大致如下 $.ajax({ type:"POST&quo ...
- Kendo MVVM 数据绑定(十) Source
Kendo MVVM 数据绑定(十) Source Source 绑定可以把 ViewModel 的值和由 Kendo 模板定义的目标元素绑定,如果 ViewModel 的值发生变化,被绑定的目标元素 ...
- JavaScript是什么
JavaScript是一种解释型语言而不是编译型语言,它往往被认为是一种脚本语言,而不被看作是一种真正的编程语言.也就是说,脚本语言比较简单,它们是非程序员所使用的编程语言. 如果一个程序员对Java ...
- [make error ]ubuntu显示不全
make时候,输出到文件里 make >&makelog 就会自动出现一个makelog 会慢一些,不要急.
- 基于FPGA的DDS任意波形发生器设计
一.简介 DDS技术最初是作为频率合成技术提出的,由于其易于控制,相位连续,输出频率稳定度高,分辨率高, 频率转换速度快等优点,现在被广泛应用于任意波形发生器(AWG).基于DDS技术的任 ...