B. Young Photographer

题目连接:

http://codeforces.com/contest/14/problem/B

Description

Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at that racetrack, equals n. And each of them regularly runs distances within a particular segment of the racetrack, which is the same for each sportsman. For example, the first sportsman runs from position a1 to position b1, the second — from a2 to b2

What is the minimum distance that Bob should move to have a chance to take pictures of each sportsman? Bob can take a picture of a sportsman, if he stands within the segment that this sportsman covers on the racetrack.

Input

The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi).

Output

Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.

Sample Input

3 3
0 7
14 2
4 6

Sample Output

1

Hint

题意

有n个区间,然后现在你在x,你需要找到一个最近的位置,这个位置覆盖了所有的区间。

题解:

线段树什么的都可以啦

对于每个区间,我都打一个标记就好了,如果现在的标记数量有n个,就说明覆盖了n次

然后扫一遍就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1006;
int a[maxn];
int main()
{int n,x;scanf("%d%d",&n,&x);for(int i=1;i<=n;i++){int l,r;scanf("%d%d",&l,&r);if(l>r)swap(l,r);a[l]++;a[r+1]--;}int tmp = 0;int ans = 1e9;for(int i=0;i<=1000;i++){tmp+=a[i];if(tmp==n)ans=min(ans,abs(i-x));}if(ans==1e9)cout<<"-1"<<endl;else cout<<ans<<endl;
}

Codeforces Beta Round #14 (Div. 2) B. Young Photographer 水题相关推荐

  1. Codeforces Beta Round #14 (Div. 2)【未完结】

    2022.3.8 题单地址:https://codeforces.com/contest/14 目录 A. Letter B. Young Photographer[差分] C. Four Segme ...

  2. Codeforces Beta Round #14 (Div. 2) E. Camels

    dp[i][j][k][l][m]填了i位,有j个极大值点,k个极小值点,倒数第二位是数字l,倒数第一位是数字m,有多少种填法.转移的时候枚举最后一位填什么就可以了. #include <bit ...

  3. Codeforces Beta Round #22 (Div. 2 Only) E. Scheme(DFS+强连通)

    题目大意 给了 n(2<=n<=105) 个点,从每个点 u 出发连向了一个点 v(共 n 条边) 现在要求添加最少的边使得整个图是一个强连通图 做法分析 这道题千万不要一般化:先求强连通 ...

  4. Codeforces Beta Round #4 (Div. 2 Only)

    Codeforces Beta Round #4 (Div. 2 Only) A 水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 ...

  5. Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树。单点更新

    http://codeforces.com/problemset/problem/91/B 题意: 给你n个数,求得i 到n中小于a[i]的最右边的a[j],然后求a[i]到a[j]之间包含了多少个数 ...

  6. codeforces水题100道 第九题 Codeforces Beta Round #63 (Div. 2) Young Physicist (math)

    题目链接:http://www.codeforces.com/problemset/problem/69/A 题意:给你n个三维空间矢量,求这n个矢量的矢量和是否为零. C++代码: #include ...

  7. Codeforces Beta Round #92 (Div. 1 Only) A. Prime Permutation 暴力

    A. Prime Permutation 题目连接: http://www.codeforces.com/contest/123/problem/A Description You are given ...

  8. Codeforces Beta Round #9 (Div. 2 Only) D. How many trees? dp

    D. How many trees? 题目连接: http://www.codeforces.com/contest/9/problem/D Description In one very old t ...

  9. Codeforces Beta Round #96 (Div. 1) D. Constants in the language of Shakespeare 贪心

    D. Constants in the language of Shakespeare Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codef ...

最新文章

  1. 计算几何题中的英语生词
  2. 设计模式系列3-----C++实现命令模式(Command Pattern)
  3. 翻译介绍15个经典的MDX查询-02and03
  4. 心得体悟帖---17、于迷茫低落处找到本心
  5. python:sort,sorted,argsort,lexsort
  6. blp模型 上读下写_CreditX在线借贷欺诈检测框架BLP
  7. Python基础(三)深浅拷贝、函数、文件处理、三元运算、递归、冒泡排序
  8. debian及ubuntu挂载本地硬盘的ISO镜像文件
  9. 批量实现ssh免交互认证
  10. 马上开课 | 第 3 期临床基因组家系分析,助力发表Case Report
  11. 求n个排序链表的交集
  12. MBR和 GPT互转导致Windows无法开机,镜像备份找不到
  13. Centos7与Windows查看硬盘序列号
  14. 【爬虫】IP代理池的总结、实现与维护,IP代理池小工具(小框架),自建代理ip池
  15. go每日新闻--2021-01-16
  16. ubuntu 网卡双网口 配置_Ubuntu双线双网卡双IP配置方法
  17. 计算机操作系统学习笔记----进程管理
  18. SQL*Loader-704: 内部错误: ulconnect: OCIServerAttach [0] SQL*Loader-704: Internal error ulconnect: OCI
  19. wGlasses AR智能眼镜正式发布!影育科技带来端云协同、软硬件及资源零代码、一体化的AR生态科技盛宴!
  20. 门禁锁加装指纹及联网控制功能

热门文章

  1. dede采集 标题不完整
  2. Embedded Linux Primer----嵌入式Linux基础教程--导论
  3. python中登录、注册操作数据库
  4. css3 text-shadow
  5. Android 学习笔记
  6. DOM对象与 JQuery对象互相转化
  7. 使用MongoDB存储Docker日志(续)
  8. 关于学习Mongodb的几篇文章
  9. Hive On Tez,Tez 和 MapReduce engine 性能对比
  10. 各种排序算法思想小结