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

poj 2456

时间:2014-10-30 20:35:04      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   os   ar   for   sp   div   

#include <iostream>
#include <cstdio>
#include <algorithm>

#define range(i,a,b) for (int i=a;i<=b;i++)

using  std::cin;
using  std::cout;
using  std::sort;

// namespace std has "left" and "right"
// if you use them as global variables,there will be an error

const int maxn = 100000;

int pos[maxn+1];

int left,right;

int n,m;

bool check(int val)
{
    int ans(1);
    int last(1);

    range(c,2,n)
        if (pos[c]-pos[last]>=val)
        {
            last = c;
            ans++;
        }
    return ans >= m;
}

int main()
{
    cin>>n>>m;

    range(i,1,n)
    {
        scanf("%d",&pos[i]);
    }

    sort(pos+1,pos+1+n);

    left = 0;
    right = pos[n] - pos[1];

    range(c,1,60)//i am lazy
    {
        int mid = (right + left) >> 1;
        if (check(mid))
        {
            left = mid;
        }
        else
        {
            right = mid;
        }
    }

    cout<<(left+right)/2;

    return 0;
}

 

poj 2456

标签:style   blog   io   color   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/dandi/p/4063473.html

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