HDUOJ----4004The Frog's Games(二分+简单贪心)
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
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<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(二分+简单贪心)的更多相关文章
- HDU 4004 The Frog's Games(二分答案)
The Frog's Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- 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) ...
- D - The Frog's Games (二分)
The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. On ...
- HDU 4004 The Frog's Games(二分)
题目链接 题意理解的有些问题. #include <iostream> #include<cstdio> #include<cstring> #include< ...
- The Frog's Games(二分)
The Frog's Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) ...
- The Frog's Games
The Frog's Games Problem Description The annual Games in frogs' kingdom started again. The most famo ...
- CF 628C --- Bear and String Distance --- 简单贪心
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...
- Uva 11729 Commando War (简单贪心)
Uva 11729 Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...
- CodeForces - 363D --二分和贪心
题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a ...
随机推荐
- C++“窗体”程序设计启蒙(之二)
[摘要]本文适合已经完整学习了C++面向对象机制,但在开发窗体程序方面还是零基础的同学.通过本文的引导进行实践体验,目的是消除同学们开发窗体程序的神奇感,为下一步的自学找到感觉.同一时候,能更深入地体 ...
- python3 urllib.request 网络请求操作
python3 urllib.request 网络请求操作 基本的网络请求示例 ''' Created on 2014年4月22日 @author: dev.keke@gmail.com ''' im ...
- 用emoji表情包来可视化北京市历史天气状况!
用emoji表情包来可视化北京市历史天气状况! 最近有了一个突如其来的想法,主要是看到了R社区有大神做了emoji表情包,并已经打通了ggplot的链接,所以想用ggplot结合emoji表情做一 ...
- 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 ...
- OTL翻译(2) -- OTL流的概念
OTL流的概念 任何的SQL语句.SQL语句块或存储过程,都是通过输入与输出变量进行处理参数与结果的. 如: 例1:一个SELECT语句把标量的输入变量作为WHERE子句部分的条件:同时SELECT部 ...
- 如何查看ETW Trace?
三种方法: LogParser Tractrpt - C:\Windows\System32 SvcTraceViewer.exe 后面的链接中有使用的详细步骤. 参考资料 ========= ...
- Reduce Task的学习笔记
MapReduce五大过程已经分析过半了.上次分析完Map的过程,着实花费了我的非常多时间.只是收获非常大,值得了额,这次用相同的方法分析完了Reduce的过程,也算是彻底摸透了MapReduce思想 ...
- effective C++中条款37:绝不又一次定义继承而来的缺省參数值
virtual 函数会动态绑定,而virtual函数的缺省參数值是静态绑定的. 用一个base类型的指针p去指向一个derived类对象.通过p调用虚函数时,会动态绑定到实际所指对象中的函数:用一个d ...
- 避免闪烁的方法(OnEraseBkgnd)
在图形图象处理编程过程中,双缓冲是一种主要的技术.我们知道,假设窗口在响应WM_PAINT消息的时候要进行复杂的图形处理,那么窗口在重绘时因为过频的刷新而引起闪烁现象. 解决这一问题的有效方法就是双缓 ...
- 没有main函数的helloworld
差点儿全部程序猿的第一堂课都是学习helloworld程序,以下我们先来重温一下经典的C语言helloworl /* hello.c */ #include <stdio.h> int m ...