比赛时看了一下这道题,,感觉挺难的,后来一位学长想了出来。赛后听他讲了一下,对他是佩服不已,,,二分+贪心,,这个跨度很大啊,,,,,,,,,还是做的题太少了,比赛时完全不知道思路是什么,,纠结,,,,,题目:
are out. The frogs was asked to jump at most m (1<= m <= n+1) times. Now the frogs want to know if they want to jump across the river, at least what ability should they have. (That is the frog's longest jump distance).
Then n lines follow. Each stands for the distance from the starting banks to the nth stone, two stone appear in one place is impossible.
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int l,n,m;
int a[500005];
bool judge(int x)
{
int pos=0,count=1;
while(count<=m)
{
count+=1;
//pos+=x;
int num=upper_bound(a+1,a+n+2,pos+x)-(a+1);
//printf("%d\n",num);
pos=a[num];
if(pos==l)
return true;
}
return false;
}
int main()
{
while(scanf("%d%d%d",&l,&n,&m)!=EOF)
{
for(int i=1;i<=n;++i)
scanf("%d",&a[i]);
a[n+1]=l;
sort(a+1,a+n+2);
int lleft=0,rright=l,mmax;
while(lleft<=rright)
{
int mid=(lleft+rright)/2;
//printf("%d %d %d \n",lleft,rright,mid);
if(judge(mid))
{
mmax=mid;
rright=mid-1;
}
else
lleft=mid+1;
}
printf("%d\n",mmax);
}
return 0;
}
本文介绍了一道编程竞赛题目——铁蛙三项之跳河挑战。任务是确定青蛙为完成跳跃所需的最短能力距离。通过二分查找与贪心算法结合的方法解决此问题,并提供了一份AC代码示例。

被折叠的 条评论
为什么被折叠?



