Codeforces Beta Round #14 (Div. 2) B. Young Photographer 水题
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 水题的更多相关文章
- Codeforces Beta Round #14 (Div. 2) C. Four Segments 水题
C. Four Segments 题目连接: http://codeforces.com/contest/14/problem/C Description Several months later A ...
- Codeforces Beta Round #4 (Div. 2 Only) A. Watermelon 水题
A. Watermelon 题目连接: http://www.codeforces.com/contest/4/problem/A Description One hot summer day Pet ...
- Codeforces Beta Round #6 (Div. 2 Only) A. Triangle 水题
A. Triangle 题目连接: http://codeforces.com/contest/6/problem/A Description Johnny has a younger sister ...
- Codeforces Beta Round #14 (Div. 2)
Codeforces Beta Round #14 (Div. 2) http://codeforces.com/contest/14 A 找最大最小的行列值即可 #include<bits/s ...
- Codeforces Beta Round #14 (Div. 2) D. Two Paths 树形dp
D. Two Paths 题目连接: http://codeforces.com/contest/14/problem/D Description As you know, Bob's brother ...
- Codeforces Beta Round #14 (Div. 2) A. Letter 水题
A. Letter 题目连接: http://www.codeforces.com/contest/14/problem/A Description A boy Bob likes to draw. ...
- Codeforces Beta Round #14 (Div. 2) D. Two Paths 树的直径
题目链接: http://codeforces.com/contest/14/problem/D D. Two Paths time limit per test2 secondsmemory lim ...
- Codeforces Beta Round #14 (Div. 2) Two Paths (树形DP)
Two Paths time limit per test 2 seconds memory limit per test 64 megabytes input standard input outp ...
- TTTTTTTTTTTTT 树的直径 Codeforces Beta Round #14 (Div. 2) D. Two Paths
tiyi:给你n个节点和n-1条边(无环),求在这个图中找到 两条路径,两路径不相交,求能找的两条路径的长度的乘积最大值: #include <iostream> #include < ...
随机推荐
- 数据库类型与JDBC TYPE 和Java类型对应关系
https://blog.csdn.net/seelye/article/details/40105969
- python学习笔记5--加密模块hashlib
import hashlib # md5 ybm_pwd='yuanbapqingsdfs234FF234HF@F' # m = hashlib.md5() # bytes_ybq = ybm_pwd ...
- [转载]Supporting OData $inlinecount with the new Web API OData preview package
http://www.strathweb.com/2012/08/supporting-odata-inlinecount-with-the-new-web-api-odata-preview-pac ...
- [整理]WebAPI中应用oData
http://www.odata.org/ http://bitoftech.net/category/odata/ http://www.hanselman.com/blog/CreatingAnO ...
- HDU 2066 一个人的旅行 最短路问题
题目描述:输入的第一行有三个数,T,S,D,T表示一共有多少条线路,S表示起点的个数,D表示终点的个数,接下来就是输入T条路的信息了,要你判断从多个起点中任意一个到多个终点中的任意的一个的最短距离是多 ...
- 日常训练赛 Problem C – Complete Naebbirac’s sequence
比赛链接https://vjudge.net/contest/256988#status/17111202012/C/0/ 大意:三个操作,使得输入的数中,从1-n,每一个数出现的次数相同. wa代码 ...
- crontab机会任务监控
<1>如何查看自己的计划任务是否成功的执行? 昨天crontab中的同步任务没有执行,不知道是什么原因没有执行,貌似任务hang住了,想查询一下crontab到底问题出在哪里,或者hang ...
- Heist
CF#509 div2 A 第一次用自己的号打CF祭. 题目描述 昨晚有一家电子商店被抢劫了. 昨天在商店里的所有键盘都是从x开始按升序编号的.例如,如果x=4,并且商店中有3个键盘,那么编号就为4, ...
- Vue学习系列---安装
一.前言 学任何东西都是有理由的,目前主要有Angular,React,Vue这三个前端MVVM框架.我选择vue原因很简单,“”入门简单“”,是的只是这个理由.相较于其他2个框架,vue的文档真的是 ...
- django orm按天统计发布单数量
夜深了,先上代码和数据,明天再实现可视化图表. from datetime import datetime, timedelta from django.http import JsonRespons ...