题意:这里有n个区间,你需要添加一个区间,使得每个区间都至少有一个共同的点在这个区间,且长度最小,输出最小的长度。

分析:找出所有区间右端点的最小值,和所有区间左端点的最大值,然后答案就是max(0, lmax - rmin)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
const int INF = 0x3f3f3f3f;
using namespace std;
const int N = 1e5 + 5;
int main()
{
int t;
scanf("%d", &t); while (t--)
{
int n;
scanf("%d", &n); int l = -INF, r = INF;
int x, y;
for (int i = 1; i <= n; ++i)
{
cin >> x >> y;
if (y < r) r = y;
if (x > l) l = x;
} printf("%d\n", max(0, l - r)); } return 0;
}

A.Math Problem的更多相关文章

  1. hdu 1757 A Simple Math Problem (乘法矩阵)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. HDU1757 A Simple Math Problem 矩阵快速幂

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. HDU 5615 Jam's math problem

    Jam's math problem Problem Description Jam has a math problem. He just learned factorization.He is t ...

  4. hdu----(5055)Bob and math problem(贪心)

    Bob and math problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. hdu------(1757)A Simple Math Problem(简单矩阵快速幂)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  6. BestCoder Round #70 Jam's math problem(hdu 5615)

    Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ...

  7. FZYZ-2071 A Simple Math Problem IX

    P2071 -- A Simple Math Problem IX 时间限制:1000MS      内存限制:262144KB 状态:Accepted      标签:    数学问题-博弈论    ...

  8. Jam's math problem(思维)

    Jam's math problem Submit Status Practice HDU 5615   Description Jam has a math problem. He just lea ...

  9. HDU 5055 Bob and math problem(结构体)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been think ...

  10. A Simple Math Problem(矩阵快速幂)(寒假闭关第一题,有点曲折啊)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. 012.Kubernetes二进制部署worker节点Flannel

    一 部署flannel 1.1 安装flannel kubernetes 要求集群内各节点(包括 master 节点)能通过 Pod 网段互联互通.flannel 使用 vxlan 技术为各节点创建一 ...

  2. 一个excel(20M)就能干趴你的poi,你信吗?

    自从上一篇:一个普通类就能干趴你的springboot,你信吗?后,很巧的是这次又发现一个问题,所以有了这篇文章,还是想沿用上篇的”流水帐“的方式查找问题和解决问题.这篇文章主要是因为使用POI导入一 ...

  3. Docker学习-Spring Boot on Docker

    1.创建spring boot项目 https://start.spring.io/ pom.xml文件新增docker支持 <build> <plugins> <plu ...

  4. Cesium坐标系及坐标转换详解

    前言 Cesium项目中经常涉及到模型加载.浏览以及不同数据之间的坐标转换,弄明白Cesium中采用的坐标系以及各个坐标系之间的转换,是我们迈向三维GIS大门的前提,本文详细的介绍了Cesium中采用 ...

  5. 关于GC(中):Java垃圾回收相关基础知识

    Java内存模型 (图源: 深入理解JVM-内存模型(jmm)和GC) 区域名 英文名 访问权限 作用 备注 程序计数器 Program Counter Register 线程隔离 标记待取的下一条执 ...

  6. 力扣(LeetCode)最后一个单词的长度 个人题解

    给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度. 如果不存在最后一个单词,请返回 0 . 说明:一个单词是指由字母组成,但不包含任何空格的字符串. 示例: 输入: &quo ...

  7. veu npm run dev指定host

    通常,我们可以在vue项目中的config/index.js指定host,,如下(解host的注释) 但是,在接手的目前项目中,解注释host后,npm run dev并有变为 http://192. ...

  8. Java——内部类详解

    说起内部类,大家肯定感觉熟悉又陌生,因为一定在很多框架源码中有看到别人使用过,但又感觉自己使用的比较少,今天我就带你具体来看看内部类. 内部类基础 所谓内部类就是在类的内部继续定义其他内部结构类. 在 ...

  9. 论文阅读:Face Recognition: From Traditional to Deep Learning Methods 《人脸识别综述:从传统方法到深度学习》

     论文阅读:Face Recognition: From Traditional to Deep Learning Methods  <人脸识别综述:从传统方法到深度学习>     一.引 ...

  10. Fortran数组、函数--xdd

    1.数组的声明 integer,parameter::num= integer::student(num) 或者 integer a() 或者 integer a(,) student()= !第一个 ...