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 ;
}

HDUOJ----4004The Frog's Games(二分+简单贪心)的更多相关文章

  1. HDU 4004 The Frog's Games(二分答案)

    The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  2. HDU 4004 The Frog's Games(二分+小思维+用到了lower_bound)

    The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  3. D - The Frog's Games (二分)

    The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. On ...

  4. HDU 4004 The Frog's Games(二分)

    题目链接 题意理解的有些问题. #include <iostream> #include<cstdio> #include<cstring> #include< ...

  5. The Frog's Games(二分)

    The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  6. The Frog's Games

    The Frog's Games Problem Description The annual Games in frogs' kingdom started again. The most famo ...

  7. CF 628C --- Bear and String Distance --- 简单贪心

    CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...

  8. Uva 11729 Commando War (简单贪心)

    Uva 11729  Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...

  9. CodeForces - 363D --二分和贪心

    题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a ...

随机推荐

  1. C++“窗体”程序设计启蒙(之二)

    [摘要]本文适合已经完整学习了C++面向对象机制,但在开发窗体程序方面还是零基础的同学.通过本文的引导进行实践体验,目的是消除同学们开发窗体程序的神奇感,为下一步的自学找到感觉.同一时候,能更深入地体 ...

  2. python3 urllib.request 网络请求操作

    python3 urllib.request 网络请求操作 基本的网络请求示例 ''' Created on 2014年4月22日 @author: dev.keke@gmail.com ''' im ...

  3. 用emoji表情包来可视化北京市历史天气状况!

    用emoji表情包来可视化北京市历史天气状况!   最近有了一个突如其来的想法,主要是看到了R社区有大神做了emoji表情包,并已经打通了ggplot的链接,所以想用ggplot结合emoji表情做一 ...

  4. Top N的MapReduce程序MapReduce for Top N items

    In this post we'll see how to count the top-n items of a dataset; we'll again use the flatland book ...

  5. OTL翻译(2) -- OTL流的概念

    OTL流的概念 任何的SQL语句.SQL语句块或存储过程,都是通过输入与输出变量进行处理参数与结果的. 如: 例1:一个SELECT语句把标量的输入变量作为WHERE子句部分的条件:同时SELECT部 ...

  6. 如何查看ETW Trace?

    三种方法: LogParser Tractrpt - C:\Windows\System32 SvcTraceViewer.exe   后面的链接中有使用的详细步骤.   参考资料 ========= ...

  7. Reduce Task的学习笔记

    MapReduce五大过程已经分析过半了.上次分析完Map的过程,着实花费了我的非常多时间.只是收获非常大,值得了额,这次用相同的方法分析完了Reduce的过程,也算是彻底摸透了MapReduce思想 ...

  8. effective C++中条款37:绝不又一次定义继承而来的缺省參数值

    virtual 函数会动态绑定,而virtual函数的缺省參数值是静态绑定的. 用一个base类型的指针p去指向一个derived类对象.通过p调用虚函数时,会动态绑定到实际所指对象中的函数:用一个d ...

  9. 避免闪烁的方法(OnEraseBkgnd)

    在图形图象处理编程过程中,双缓冲是一种主要的技术.我们知道,假设窗口在响应WM_PAINT消息的时候要进行复杂的图形处理,那么窗口在重绘时因为过频的刷新而引起闪烁现象. 解决这一问题的有效方法就是双缓 ...

  10. 没有main函数的helloworld

    差点儿全部程序猿的第一堂课都是学习helloworld程序,以下我们先来重温一下经典的C语言helloworl /* hello.c */ #include <stdio.h> int m ...