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的更多相关文章

  1. CF1029C Maximal Intersection 暴力枚举

    Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input standar ...

  2. 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 ...

  3. Codeforces | CF1029C 【Maximal Intersection】

    论Div3出这样巨水的送分题竟然还没多少人AC(虽说当时我也没A...其实我A了D...逃) 这个题其实一点都不麻烦,排序都可以免掉(如果用\(priority \_ queue\)的话) 先考虑不删 ...

  4. CodeForces C. Maximal Intersection

    http://codeforces.com/contest/1029/problem/C You are given nn segments on a number line; each endpoi ...

  5. F - Maximal Intersection --------暴力求解题

    You are given n segments on a number line; each endpoint of every segment has integer coordinates. S ...

  6. C. Maximal Intersection(STL)

    这道题,关键在于怎么求多个区间的交集,使用multiset就可以 分别将 r , l 存在不同的mutiset中. 然后,我们来看一下 是不是 交集的 l 是最大的, 交集的 r 是最小的 #incl ...

  7. CF C. Maximal Intersection(贪心 || STL)

    题意 给你N个线段(一条直线上),问删去一个之后,最长公共长度 : 分析:首先我们得先知道n条线段公共的线段一定是(LMAX,RMIN) ,那我们可以先排序,然后枚举删除边: #include< ...

  8. Codeforces Round #506 (Div. 3) 题解

    Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...

  9. cf 1029 C

    C. Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. oracle rollback 观察时间

    ###########issue 0: db alert 有如下提示, thread 1 cannot allocatete new log, sequenec 1111 通过检查v$log ,发现1 ...

  2. Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟

    http://codeforces.com/contest/732/problem/D 这题我发现很多人用二分答案,但是是不用的. 我们统计一个数值all表示要准备考试的所有日子和.+m(这些时间用来 ...

  3. 《java学习三》jvm性能优化-------调优

    常见参数配置 -XX:+PrintGC      每次触发GC的时候打印相关日志 -XX:+UseSerialGC      串行回收 -XX:+PrintGCDetails  更详细的GC日志 -X ...

  4. c# 视频播放

    发表于: 2003-10-15 20:39:21 搞定了,嘿嘿!首先非常感谢zoujiaming在邮件中给我指了条路:用C#调用API搞定!!!使用的是mciSendString API函数主要参考了 ...

  5. 常用API(Object、String、StringBuffer、用户登陆注册)

    常用API 今日内容介绍 u Object u String u StringBuilder 第1章 Java的API及Object类 在以前的学习过程中,我们都在学习对象基本特征.对象的使用以及对象 ...

  6. Java基础(变量、运算符)

    第2天 Java基础语法 今日内容介绍 u 变量 u 运算符 第1章 变量 1.1 变量概述 前面我们已经学习了常量,接下来我们要学习变量.在Java中变量的应用比常量的应用要多很多.所以变量也是尤为 ...

  7. eclipse中安装lombok插件

    一:下载lombok 下载地址:https://projectlombok.org/downloads/lombok.jar 或者访问官网下载  https://projectlombok.org/ ...

  8. html的文档设置标记上(格式标记)4-5

    <html> <head> <title>第四课的标题及第五课的标题</title> <meta charset="utf-8" ...

  9. 零基础逆向工程17_PE结构01_PE头解析_手动

    PE文件的两种状态 1.在硬盘中 节省硬盘空间 硬盘对齐 内存对齐 2.在内存中 3.PE磁盘文件与内存映像结构图 PE文件为什么要分节 -- 手动解析:PE文件 分析软件:飞鸽传书http://ww ...

  10. Ubuntu 设置静态ip地址

    1. 找到文件并作如下修改: sudo vim /etc/network/interfaces 修改如下部分: auto eth0iface eth0 inet staticaddress 192.1 ...