比赛 20151207初中练习 评测结果 AAAAAAAAAA
题目名称 跳石头 最终得分 100
用户昵称 ミント 运行时间 0.035 s
代码语言 C++ 内存使用 0.51 MiB
提交时间 2015-12-07 20:54:13
显示代码纯文本
//据说二分答案是正解, 刷了半天空间才想出大概思路.
//凑合着看吧...大概.
#include <fstream>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;

ifstream fin("2015stone.in");
ofstream fout("2015stone.out");

const int maxn = 50000 + 2 + 200;
int l, n, m;
int stone[maxn];
 
int main()
{
    fin>>l>>n>>m;
	
    for(int i=1;i<=n;i++)
		fin>>stone[i];
	
	stone[n+1] = l;
	n += 2;
	
    sort(stone, stone+n, less<int>());
	
    int left = 0;
	int right = l + 1;
	
	while (right-1>left)
	{
		bool flag = true;
		int mid = (left + right) / 2;
		
		int pos = 0;
		for(int i=1;i<n-m;++i)
		{ 
			int now = pos+1;
			while (now<n&&stone[now]-stone[pos]<mid)
				now++;
		    if(now==n)
			{
				flag = false;
				break;
			}
		    pos = now;
		}
		if (flag)
			left = mid;
		else
			right = mid;
	}
	
    fout<<left<<endl;
	
	fin.close();
	fout.close();
	
	return 0;
}