14B - Young Photographer
来源:互联网 发布:淘宝怎么做百度推广 编辑:程序博客网 时间:2024/04/29 15:32
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.
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 integersai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi).
Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1.
3 30 714 24 6
1
给出一些区间,和一个点,问这些区间的公共部分距离这个点的最近距离,如果不存在,那么输出-1
各种小细节错误,各种不注意
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;int main(){ int n,m,x[1005]={0}; scanf("%d%d",&n,&m); for(int i=0;i<n;++i) { int a,b; scanf("%d%d",&a,&b); if(a>b) { swap(a,b); } for(int j=a;j<=b;++j) { ++x[j]; } } int bg=0,ed=0,i=0; while(i<1005&&x[i]!=n) { ++i; } bg=i; while(i<1005&&x[i]==n) { ++i; } ed=i-1; int ans; if(bg==1005) { ans=-1; } else { if(m>=bg&&m<=ed) { ans=0; } else { ans=min(abs(m-bg),abs(m-ed)); } } printf("%d\n",ans); return 0;}
- 14B - Young Photographer
- codeforces 14B. Young Photographer
- CodeForces 14B Young Photographer
- B、Young Tableau
- Codeforces--237B--Young Table(模拟)
- Codeforces 237B Young Table 【构造】
- CodeForces - 237B Young Table (模拟)
- Nudnik Photographer
- C. Photographer
- 7月12日B题:Young Table
- Codeforces Round #147 (Div. 2) / 237B Young Table (搜索)
- Codeforces Round #147 (Div. 2) B. Young Table
- 【Codeforces 237B Young Table】+ map 数组构造
- 1260. Nudnik Photographer
- 1260. Nudnik Photographer dp
- Ural 1260. Nudnik Photographer
- URAL 1260. Nudnik Photographer
- Photographer (SDUT 2063)
- ubuntu linux 下建立 纯L2TP 服务端和客户端
- PHP 开发者该知道的 5 个 Composer 小技巧
- Thread Join学习
- Swing 用户注册。。
- xxxx
- 14B - Young Photographer
- this关键字
- 交叉编译ncurses库
- MySQL优化之三--Mysql服务参数配置
- android使用NumberPicker时屏蔽掉点击可输入问题
- UVALive 3720 Highways
- 移动端开发:使用jQuery Mobile还是Zepto
- 防御手段总结
- Android面试知识点1