码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 14B Young Photographer

时间:2016-08-19 20:40:22      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

题目链接:http://codeforces.com/problemset/problem/14/B

题意:一条一维坐标轴,一个拍摄者在x0的位置,如果他在一个运动员运动的周期范围内(a1~b1),他就可以排到这个运动员,问你最小走几步的位置可以拍到所有运动员,若没有输出-1。(a可能大于b)

数据范围:运动员人数是不大于100,位置是0~1000

分析:暴力枚举1000个点在所有ab范围内并且离x0最近的,若没有就输出-1。

代码:

技术分享
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdlib>
#include<iomanip>
#include<string>
#include<vector>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
#define Max(a,b) (a>b)?a:b
#define lowbit(x) x&(-x)

int main()
{
    int n,a[5005]={0},x,y,ans=INF,x0;
    scanf("%d%d",&n,&x0);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&x,&y);
        if(x>y)
            swap(x,y);
        for(int j=x;j<=y;j++)
        {
            a[j]++;
            if(a[j]==n)
            {
                if(abs(j-x0)<ans)
                    ans=abs(j-x0);
            }
        }
    }
    if(ans==INF)
        ans=-1;
    printf("%d\n",ans);
}
View Code

 

CodeForces 14B Young Photographer

标签:

原文地址:http://www.cnblogs.com/wwdf/p/5788791.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!