http://codeforces.com/contest/1029/problem/C

从第一天吃晚饭做到第二天吃完饭……你无法想象我的代码曾经150行 o( ̄┰ ̄*)ゞ

找到所有线段最远的左边和最近的右边,当一个线段的左边或右边与上述重合就尝试删除。

 1 import java.util.Arrays;
2 import java.util.Scanner;
3
4 public class A {
5 public static void main(String[] args) {
6 Scanner io = new Scanner(System.in);
7 int n = io.nextInt();
8 if (n == 1) {
9 System.out.println(-(io.nextInt() - io.nextInt()));
10 return;
11 }
12 int[] a = new int[n];
13 int[] b = new int[n];
14 int[] A = new int[n];
15 int[] B = new int[n];
16 int[] minLeft = new int[n];
17 int[] minRight = new int[n];
18 int[] maxLeft = new int[n];
19 int[] maxRight = new int[n];
20
21 for (int i = 0; i < n; i++) {
22 A[i] = a[i] = io.nextInt();
23 B[i] = b[i] = io.nextInt();
24 if (i != 0) {
25 maxLeft[i] = Math.max(maxLeft[i - 1], a[i]);
26 minLeft[i] = Math.min(minLeft[i - 1], b[i]);
27 } else {
28 maxLeft[0] = a[0];
29 minLeft[0] = b[0];
30 }
31 }
32 for (int i = n - 1; i >= 0; i--) {
33 if (i != n - 1) {
34 maxRight[i] = Math.max(maxRight[i + 1], a[i]);
35 minRight[i] = Math.min(minRight[i + 1], b[i]);
36 } else {
37 maxRight[n - 1] = a[n - 1];
38 minRight[n - 1] = b[n - 1];
39 }
40 }
41 Arrays.sort(A);
42 Arrays.sort(B);
43
44 int len = 0,min,max;
45 for (int i = 0; i < n; i++) {
46 if (a[i] == A[n - 1] || b[i] == B[0]) {
47 if (i == 0) {
48 min = minRight[1];
49 max = maxRight[1];
50 } else if (i == n - 1) {
51 min = minLeft[n - 2];
52 max = maxLeft[n - 2];
53 } else {
54 min = Math.min(minLeft[i - 1], minRight[i + 1]);
55 max = Math.max(maxLeft[i - 1], maxRight[i + 1]);
56 }
57 len = Math.max(min - max, len);
58 }
59 }
60 System.out.println(len);
61 }
62 }

codeforce C. Maximal Intersection的更多相关文章

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

  2. CF1029C Maximal Intersection 暴力枚举

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

  3. CodeForces C. Maximal Intersection

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

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

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

  5. C. Maximal Intersection(STL)

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

  6. Codeforces | CF1029C 【Maximal Intersection】

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

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

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

  8. CF1029C Maximal Intersection

    https://www.luogu.org/problem/show?pid=CF1029C #include<bits/stdc++.h> using namespace std ; # ...

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

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

  10. cf 1029 C

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

随机推荐

  1. [图像处理] YUV图像处理入门4

    9 yuv420图像截取 本程序中的函数主要是对YUV420P视频数据流的第一帧图像进行截取.类似opencv中的rect函数,函数的代码如下所示: /** * @file 9 yuv_clip.cp ...

  2. [常用工具] Caffe ssd常见问题集合

    1 Check failed: a <= b <0 vs -1.19209e-007> 网上办法是注释掉 CHECK_LE(a, b),但是这样会出大问题.解决办法见2. 如果注释掉 ...

  3. emqtt-bench

    安装 安装环境:Centos7 安装包:emqtt-bench-0.4.6-alpha.2-centos7-amd64.tar.gz 建议使用已编译好的发行包进行安装,源码编译已踩坑. # 创建存放目 ...

  4. java进阶篇——Stream流编程

    Stream流 函数式接口 1.消费型接口--Consumer @FunctionalInterface public interface Consumer<T> { /** * 对给定的 ...

  5. NetCore模型绑定之FromBodyFromUriFromQueryFromRoute

    title: .Net Core模型绑定之FromBody.FromUri.FromQuery.FromRoute categories: 后端 date: 2022-10-29 17:21:11 t ...

  6. [数据结构]Dijkstra算法求单源最短路径

    概念 求带权有向图中某个源点到其余各个顶点的最短路径,最常用的是Dijkstra算法.该算法设置一个集合S记录已求得的最短路径的顶点,可用一个数组s[]来实现,初始化为0,当s[Vi]=1时表示将顶点 ...

  7. 今日实际操作----Dart Mac开发与运行环境配置 配置.bash_profile

    Mac 打开.编辑 .bash_profile 文件 一般在Mac上配置环境变量时经常要创建.编辑 .bash_profile文件.创建该文件时一般都会选择在当前用户目录下,即Mac下的.bash_p ...

  8. SpringCloud————>了解什么是微服务技术

    SpringCloud是Spring为微服务架构思想做的一个一站式实现.从某种程度是可以简单的理解为,微服务是一个概念.一个项目开发的架构思想.SpringCloud是微服务架构的一种java实现. ...

  9. python开发简单的命令行工具

    介绍 Python模块argparse,这是一个命令行选项,参数和子命令的解释器,使用该模块可以编写友好的命令行工具,在程序中定义好需要的参数,argparse将弄清楚如何解析 sys.argv中的参 ...

  10. CF1466H Finding satisfactory solutions

    CF1466H Finding satisfactory solutions 这题厉害了! 先考虑已知 \(b\) 如何求合法的 \(a\).由于是排列,就想和置换环扯上关系.考虑将 \(i\) 与 ...