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 ...
随机推荐
- unity3d-地图制作之光照贴图Lightmapping
今天无聊随便翻看了暗黑战神的场景资源,发现了一个以前没怎么注意的静态场景优化问题. 什么是静态场景,也就是说这个场景是不会变化.比如MMO游戏中选择人物的场景. 就拿默认的暗黑战神的选择人物场景来看, ...
- 【POJ】【2068】Art Gallery
计算几何/半平面交 裸的半平面交,关于半平面交的入门请看神犇博客:http://blog.csdn.net/accry/article/details/6070621 然而代码我是抄的proverbs ...
- Informatica 常用组件Expression之一 概述
转换类型:被动.已连接 可以在写入目标前,使用表达式转换计算单行中的值.例如,您可能需要调整员工薪酬.连接姓名或将字符串转换为数字.您可以使用表达式转换执行任意非聚合计算.在将结果输出 ...
- Eclipse 中java跨工程调用类
在Eclipse中,有时候需要跨工程调用其他工程中的方法.如下面有两个Java Project : 如果要在A工程中调用B工程中的类,可以将B工程添加到A工程中: A---- >Build Pa ...
- 如何在脚本中执行SQL语句并获得结果输出?
这里需要用到的工具叫做sqlcmd.exe, 它随SQL server的安装而安装. 该可执行程序的位置在: C:\Program Files\Microsoft SQL Server\xxx\Too ...
- EasyUI中combobox的使用方法和一个代码实例
一.easyUI中select下拉框动态添加option选项 问题:想在combobox的下拉项里动态添加一些内容,但是添加不成功.因为jquery easyui的下拉列表combobox是用DIV模 ...
- 协定须要双工,可是绑定“WSHttpBinding”不支持它或者因配置不对而无法支持它
协定须要双工,可是绑定"WSHttpBinding"不支持它或者因配置不对而无法支持它 下面两种情况,我都遇到过. 一, < endpoint address =" ...
- Terminix:基于 GTK3 的平铺式 Linux 终端模拟器
现在,你可以很容易的找到大量的 Linux 终端模拟器,每一个都可以给用户留下深刻的印象.但是,很多时候,我们会很难根据我们的喜好来找到一款心仪的日常使用的终端模拟器.这篇文章中,我们将会推荐一款叫做 ...
- [Algorithm] Count Negative Integers in Row/Column-Wise Sorted Matrix
// Code goes here function countNegative (M, n, m) { count = ; i = ; j = m - ; && i < n) ...
- Linux下时间格式转换及获取方法
Linux下使用clock_gettime给程序计时 #include <stdio.h> #include <unistd.h> #include <stdlib.h& ...