The Frog's Games

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 3263    Accepted Submission(s): 1596

Problem Description
The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over the river. The width of the river is L (1<= L <= 1000000000). There are n (0<= n <= 500000) stones lined up in a straight line from one side to the other side of the river. The frogs can only jump through the river, but they can land on the stones. If they fall into the river, they
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).
 
Input
The input contains several cases. The first line of each case contains three positive integer L, n, and m.
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.
 
Output
For each case, output a integer standing for the frog's ability at least they should have.
 
Sample Input
6 1 2 2 25 3 3 11 2 18
 
Sample Output
4 11
 
Source
 参考别人的思路做的,挫....
利用二分来选择适合的数。。。然后再验证,是枚举的优化版。 好吧,这个思路是别人的 ,我还是太挫啦
代码:

 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<functional>
const int maxn= ;
using namespace std;
int stone[maxn],n,m;
bool judge(int dis)
{
int i=,pre=,count=;
while(i<=n+)
{
count++;
if(dis<stone[i]-stone[i-]) return false ; //这个石头跳不过去,所以失败
while (i<=(n+)&&dis>=stone[i]-stone[pre]) i++;
pre=i-;
if(count>m) return false ;
}
return true ;
}
int main()
{
int length,i;
while(scanf("%d%d%d",&length,&n,&m)!=EOF)
{
memset(stone,,sizeof(int)*(n+));
for(i=;i<=n;i++)
scanf("%d",&stone[i]);
stone[i]=length;
sort(stone,stone+(n+),less<int>()); //升序安放stone
int ans,low=,high=length;
while(low<=high)
{
ans=(low+high)/; //跳这么远的时候能否满足要求
if(ans*m>=length&&judge(ans)) high=ans-;
else low=ans+;
}
printf("%d\n",low);
}
return ;
}

最新文章

  1. Scala入门之Array
  2. U-boot.lds文件分析
  3. hdu4547 lca tarjan
  4. POJ2253 Frogger
  5. return break continue
  6. Redis - hash类型操作
  7. Linux之select系统调用_2
  8. Otto开发初探——微服务依赖管理新利器
  9. 理解RunLoop
  10. connot find one or more components. please reinstall the application
  11. BZOJ2300: [HAOI2011]防线修建
  12. 【英国毕业原版】-《伯明翰城市大学毕业证书》BCU一模一样原件
  13. Java多线程基础(二)
  14. Promise的两种处理异步的方式
  15. jdk的下载
  16. linux 学习之路:mkdir命令使用
  17. SwipeableFlatList 实现类似于QQ列表滑动
  18. 训练题(代码未检验)(序列前k大和问题)
  19. jqprint的网页打印,打印预览可以包含图片
  20. [z]dbms_stats.lock_table_stats对于没有统计信息的表分区同样有效

热门文章

  1. Eclipse 搭建struts2 spring3 hibernate3环境实战 待完善
  2. 基于Qt的wifi智能小车的制作(一)
  3. iOS开发--整理常用的第三方资源
  4. Android之WifiManager
  5. CF 463D Gargari and Permutations [dp]
  6. CloudStack无法添加模板和iso
  7. 我对REST的理解
  8. [NPM] Execute Code from a Remote GitHub Branch with npx
  9. IOS遇到的问题总结
  10. Asp.net 生成静态页面