关闭

跳石头

46人阅读 评论(0) 收藏 举报
分类:

</pre></h1><h2 id="description" style="margin: 0.8em 0px; padding: 0px; box-sizing: border-box; color: rgb(85, 85, 85); font-family: 'microsoft yahei'; line-height: 35px;"><span style="font-size:24px;"><a target=_blank name="t1" style="box-sizing: border-box; color: rgb(12, 137, 207);"></a>Description</span></h2><p style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 14px; line-height: 35px; margin-top: 0px; margin-bottom: 1.1em; padding-top: 0px; padding-bottom: 0px; box-sizing: border-box;">一年一度的“跳石头”比赛又要开始了! <br style="box-sizing: border-box;" />这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石。 <br style="box-sizing: border-box;" />组委会已经选择好了两块岩石作为比赛起点和终点。 <br style="box-sizing: border-box;" />在起点和终点之间,有 N 块岩石(不含起点和终 点的岩石)。 <br style="box-sizing: border-box;" />在比赛过程中,选手们将从起点出发,每一步跳向相邻的岩石,直至到达终点。 <br style="box-sizing: border-box;" />为了提高比赛难度,组委会计划移走一些岩石,使得选手们在比赛过程中的最短跳 跃距离尽可能长。 <br style="box-sizing: border-box;" />由于预算限制,组委会至多从起点和终点之间移走 M 块岩石(不能 移走起点和终点的岩石)。</p><hr style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 14px; font-weight: bold; line-height: 35px; box-sizing: border-box; margin: 2em 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-style: solid; border-top-color: rgba(128, 128, 128, 0.0980392);" /><h2 id="input" style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; line-height: 35px; margin: 0.8em 0px; padding: 0px; box-sizing: border-box;"><span style="font-size:24px;"><a target=_blank name="t2" style="box-sizing: border-box; color: rgb(12, 137, 207);"></a>Input</span></h2><p style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 14px; line-height: 35px; margin-top: 0px; margin-bottom: 1.1em; padding-top: 0px; padding-bottom: 0px; box-sizing: border-box;">输入第一行包含三个整数 L,N,M,分别表示起点到终点的距离,起点和终点之间的岩石数,以及组委会至多移走的岩石数。 <br style="box-sizing: border-box;" />接下来 N 行,每行一个整数,第 i 行的整数 Di(0 < Di < L)表示第 i 块岩石与起点的距离。 <br style="box-sizing: border-box;" />这些岩石按与起点距离从小到大的顺序给出,且不会有两个岩石出现在同一个位置。</p><hr style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 14px; font-weight: bold; line-height: 35px; box-sizing: border-box; margin: 2em 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-style: solid; border-top-color: rgba(128, 128, 128, 0.0980392);" /><h2 id="output" style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; line-height: 35px; margin: 0.8em 0px; padding: 0px; box-sizing: border-box;"><span style="font-size:24px;"><a target=_blank name="t3" style="box-sizing: border-box; color: rgb(12, 137, 207);"></a>Output</span></h2><p style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 14px; line-height: 35px; margin-top: 0px; margin-bottom: 1.1em; padding-top: 0px; padding-bottom: 0px; box-sizing: border-box;">输出只包含一个整数,即最短跳跃距离的最大值。</p><hr style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 14px; font-weight: bold; line-height: 35px; box-sizing: border-box; margin: 2em 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-style: solid; border-top-color: rgba(128, 128, 128, 0.0980392);" /><h2 id="sample-input" style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; line-height: 35px; margin: 0.8em 0px; padding: 0px; box-sizing: border-box;"><span style="font-size:24px;"><a target=_blank name="t4" style="box-sizing: border-box; color: rgb(12, 137, 207);"></a>Sample Input</span></h2><blockquote style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 14px; line-height: 35px; box-sizing: border-box; margin: 0px 0px 1.1em; padding: 15px 20px; border-left-width: 10px; border-left-style: solid; border-left-color: rgba(128, 128, 128, 0.0745098); background-color: rgba(128, 128, 128, 0.0470588); border-top-left-radius: 0px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 0px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; box-sizing: border-box; line-height: 1.25;">25 5 2 <br style="box-sizing: border-box;" />2 <br style="box-sizing: border-box;" />11 <br style="box-sizing: border-box;" />14 <br style="box-sizing: border-box;" />17 <br style="box-sizing: border-box;" />21</p></blockquote><hr style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 14px; font-weight: bold; line-height: 35px; box-sizing: border-box; margin: 2em 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-style: solid; border-top-color: rgba(128, 128, 128, 0.0980392);" /><h2 id="sample-output" style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; line-height: 35px; margin: 0.8em 0px; padding: 0px; box-sizing: border-box;"><span style="font-size:24px;"><a target=_blank name="t5" style="box-sizing: border-box; color: rgb(12, 137, 207);"></a>Sample Output</span></h2><blockquote style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 14px; line-height: 35px; box-sizing: border-box; margin: 0px 0px 1.1em; padding: 15px 20px; border-left-width: 10px; border-left-style: solid; border-left-color: rgba(128, 128, 128, 0.0745098); background-color: rgba(128, 128, 128, 0.0470588); border-top-left-radius: 0px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 0px;"><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; box-sizing: border-box; line-height: 1.25;">4</p></blockquote><hr style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 14px; font-weight: bold; line-height: 35px; box-sizing: border-box; margin: 2em 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-style: solid; border-top-color: rgba(128, 128, 128, 0.0980392);" /><h2 id="hint" style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; line-height: 35px; margin: 0.8em 0px; padding: 0px; box-sizing: border-box;"><span style="font-size:24px;"><a target=_blank name="t6" style="box-sizing: border-box; color: rgb(12, 137, 207);"></a>HINT</span></h2><p style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 14px; line-height: 35px; margin-top: 0px; margin-bottom: 1.1em; padding-top: 0px; padding-bottom: 0px; box-sizing: border-box;">对于样例: <br style="box-sizing: border-box;" />将与起点距离为 2 和 14 的两个岩石移走后,最短的跳跃距离为 4(从与起点距离17 的岩石跳到距离 21 的岩石,或者从距离 21 的岩石跳到终点)。</p><p style="color: rgb(85, 85, 85); font-family: 'microsoft yahei'; font-size: 14px; line-height: 35px; margin-top: 0px; margin-bottom: 1.1em; padding-top: 0px; padding-bottom: 0px; box-sizing: border-box;">对于20%的数据,0≤M≤N≤10。 <br style="box-sizing: border-box;" />对于50%的数据,0≤M≤N≤100。 <br style="box-sizing: border-box;" />对于100%的数据,0≤M≤N≤50000,1≤L≤1000000000。</p><div style="color: rgb(153, 153, 153); font-family: 'YaHei Consolas Hybrid', Consolas, 'Lucida Console', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace, 宋体; font-size: 14px; font-weight: bold; line-height: 21px;"><pre style="margin-top: 0px; margin-bottom: 0px; word-wrap: break-word; word-break: break-all; font-family: 'YaHei Consolas Hybrid', Consolas, 'Lucida Console', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace, 宋体; color: rgb(51, 51, 51); font-size: 14px; line-height: 21px; background-color: rgb(255, 255, 255);"><pre name="code" class="cpp">#include<cstdio>
#include<cmath>
using namespace std;
int D[51000]={0},ans,L,N,M,mid;
int Del(int x,int y)
{
	int i=x;
	while(D[i]-D[x-1]<mid&&i<=y)
	{
		ans++;	i++;
	}
	return i;
}
int main()
{
	scanf("%d%d%d",&L,&N,&M);
	for(int i=1;i<=N;i++)	scanf("%d",&D[i]);
	D[N+1]=L;
	int l=0,r=0x7fffffff;
	while(l<r)
	{
		mid=ceil((l+r)/2.0);
		int x=1,y=N;
		ans=0;
		while(D[x]<mid)	{ans++;x++;}
		while(L-D[y]<mid&&x<=y){ans++;y--;}
		while(x<y)	x=Del(x+1,y);
		if(ans>M)	r=mid-1;
		else l=mid;
	}
	printf("%d",l);
	return 0;
}


</pre><span style="font-family:YaHei Consolas Hybrid, Consolas, Lucida Console, Bitstream Vera Sans Mono, Courier New, Courier, monospace, 宋体;color:#333333;"><span style="font-size: 14px; line-height: 21px;"></span></span>
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:49次
    • 积分:10
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档
    阅读排行
    评论排行