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 ...
随机推荐
- hdu 3123 GCC (2009 Asia Wuhan Regional Contest Online)
GCC Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Subm ...
- 【BZOJ】【3503】【CQOI2014】和谐矩阵
高斯消元解Xor方程组 Orz ZYF o(︶︿︶)o 唉我的数学太烂了…… 错误思路:对每个格点进行标号,然后根据某5个异或和为0列方程组,高斯消元找自由元……(目测N^3会TLE) ZYF的正确思 ...
- 20 个具有惊艳效果的 jQuery 图像缩放插件
jQuery相对与Flash的魔力已经贯穿整个网络.尽管,Flash层被认为是用于网页设计的首选,然而随着jQuery的出现,以及他的酷似Flash的交互式特效使得网页更加的优雅——Flash开始靠边 ...
- jquery获取元素各种宽高及页面宽高总结
window.onload=function(){ var a = $("#div").width(),//width()返回元素的宽高,不包括padding/border/mar ...
- 【北京】低价出售C/C++经典书籍
都非常新 C++程序设计 5元 高质量C/C++编程指南 8元 C++对象模型 10元 STL源代码剖析 12元 深入浅出MFC 10元 设计模式 10元 C++ primer 8元 面向对象 ...
- XML基础以及用DOM4j读取数据
都知道,HTML被设计用来显示数据,XML被设计用来保存.数据传输.而我们平时经经常使用的无非是保存数据.读取数据.所以这里主要介绍XML相关基础内容.以及用DOM4j来存取XML的数据. 以下简单介 ...
- css选择器顺序的小技巧
在线演示 本地下载 css的选择器的顺序其实很有意思,如果应用的好的话,可以做一些简单的逻辑出来,配合上css3,就可以尽可能的脱离js了. 这里的演示是一个带有hover事件的四张照片,效果来自一个 ...
- 11个实用的CSS学习工具
1. 盒子模型的幻灯片 通过3D转换效果产生的互动的幻灯片.按向左或向右箭头键切换,全屏观看会有更好的效果. 2. CSS Diner 通过一个简单的小游戏让你学习CSS selector,输入正确的 ...
- Android控件之HorizontalScrollView 去掉滚动栏
在默认情况下.HorizontalScrollView控件里面的内容在滚动的情况下,会出现滚动栏,为了去掉滚动栏.仅仅须要在<HorizontalScrollView/>里面加一句 ...
- javascript:void(0) 真正含义
大家常见这种代码: <a href="javascript:doTest2();void(0);">here</a> 但这儿的void(0)到底是何含义呢? ...