http://poj.org/problem?id=3258

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=50005;
int Dist[N];
int L,n,m;
bool toosmall(int k)
{
    int sum=0;
    int pre=0;
    for(int i=1;i<=n;++i)
    {
        if(Dist[i]-pre<k)
        {
            ++sum;
        }
        else
        {
            pre=Dist[i];
        }
    }
    if(Dist[n+1]-Dist[n]<k)
    ++sum;
    if(sum>m)
    return false;
    return true;
}
int main()
{
    while(cin>>L>>n>>m)
    {
         Dist[0]=0;
         Dist[n+1]=L;
         int high=L;
         int low=L;
         for(int i=1;i<=n;++i)
         {
             cin>>Dist[i];
             if(Dist[i]-Dist[i-1]<low)
             {
                 low=Dist[i]-Dist[i-1];
             }
         }
         low=min(low,Dist[n+1]-Dist[n]);
         sort(Dist,Dist+n+2);
         int mid=(high+low)/2;
         while(low<=high)
         {
             if(toosmall(mid))
             {
                 low=mid+1;
             }
             else
             {
                 high=mid-1;
             }
             mid=(high+low)/2;
         }
         cout<<high<<endl;
    }

	return 0;
}
posted on 2012-05-08 18:56  夜->  阅读(181)  评论(0编辑  收藏  举报