Once upon a time, there is a little frog called Matt. One day, he came to a river.

The river could be considered as an axis.Matt is standing on the left bank now (at position 0). He wants to cross the river, reach the right bank (at position M). But Matt could only jump for at most L units, for example from 0 to L.

As the God of Nature, you must save this poor frog.There are N rocks lying in the river initially. The size of the rock is negligible. So it can be indicated by a point in the axis. Matt can jump to or from a rock as well as the bank.

You don't want to make the things that easy. So you will put some new rocks into the river such that Matt could jump over the river in maximal steps.And you don't care the number of rocks you add since you are the God.

Note that Matt is so clever that he always choose the optimal way after you put down all the rocks.

InputThe first line contains only one integer T, which indicates the number of test cases.

For each test case, the first line contains N, M, L (0<=N<=2*10^5,1<=M<=10^9, 1<=L<=10^9).

And in the following N lines, each line contains one integer within (0, M) indicating the position of rock.OutputFor each test case, just output one line “Case #x: y", where x is the case number (starting from 1) and y is the maximal number of steps Matt should jump.Sample Input

2
1 10 5
5
2 10 3
3
6

Sample Output

Case #1: 2
Case #2: 4

打错题号就进来了……看了看还挺有挑战性的

贪心

青蛙会选择最优策略(有丰富的人生经验?),最远能跳L,为了最大化它跳的次数,我们要尽量在当前位置x+1和x+L+1的位置放石头,这样它就不得不跳两次。

计算是要统计上次青蛙跳跃距离/(L+1)的余数last,和当前位置距离下一块石头的距离x综合考虑,若last+x>L+1,还可以多放块石头让它跳。

http://blog.csdn.net/u014569598/article/details/39471913

↑这里有张图比较直观

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,L;
int a[mxn];
int main(){
int i,j;
int T=read();
int cas=;
while(T--){
n=read();m=read();L=read();
for(i=;i<=n;i++)a[i]=read();
a[++n]=m;
sort(a+,a+n+);
int left=L;
int ans=;
for(i=;i<=n;i++){
int mod=(a[i]-a[i-])%(L+);
int dis=(a[i]-a[i-])/(L+);
if(left+mod<L+){
left=left+mod;
ans+=dis*;
}
else{
left=mod;
ans+=dis*+;
}
}
printf("Case #%d: %d\n",++cas,ans);
}
return ;
}

HDU5037 Frog的更多相关文章

  1. hdu5037 Frog (贪心)

    http://acm.hdu.edu.cn/showproblem.php?pid=5037 网络赛 北京 比较难的题 Frog Time Limit: 3000/1500 MS (Java/Othe ...

  2. [LeetCode] Frog Jump 青蛙过河

    A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...

  3. CF #305 (Div. 2) C. Mike and Frog(扩展欧几里得&&当然暴力is also no problem)

    C. Mike and Frog time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. Frog Jump

    A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...

  5. POJ 1054 The Troublesome Frog

    The Troublesome Frog Time Limit: 5000MS Memory Limit: 100000K Total Submissions: 9581 Accepted: 2883 ...

  6. Leetcode: Frog Jump

    A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...

  7. hdu 4004 The Frog's Games

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004 The annual Games in frogs' kingdom started again ...

  8. HDU 5578 Friendship of Frog 水题

    Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  9. Eat that Frog

    Eat that Frog,中文翻译过来就是“吃掉那只青蛙”.不过这里并不是讨论怎么去吃青蛙,而是一种高效的方法. Eat that Frog是Brian Tracy写的一本书(推荐阅读).这是一个很 ...

随机推荐

  1. 【Effective C++ 读书笔记】条款02: 尽量以 const, enum, inline 替换 #define

    条款02: 尽量以 const, enum, inline 替换 #define 这个条款或许可以改为“宁可以编译器替换预处理器”. 编译过程: .c文件--预处理-->.i文件--编译--&g ...

  2. 传输控制协议(TCP)

    传输控制协议(TCP)[来自Unix网络编程(卷一)第2章] 1.TCP是一个面向连接.可靠性的传输协议: 2.TCP含有用于动态估算客户与服务器之间往返时间(RTT)的算法,以便它知道等待一个确认需 ...

  3. composer环境安装

    PHP很多优秀的框架,例如Laravel等等,镜像都在国外,相关的包管理工具Composer也是在国外,所以安装失败的可能性很大,题主所示的就是因为连不上Composer.解决方法如下: 进入官网, ...

  4. C语言数组篇(一)一维数组

       0.  数组的两种表现形式         一种是常见的a[10];         //初学者常用         另一种是用指针表示的数组.   //实际工程使用.常用于参数传递       ...

  5. Numpy数据存取与函数

    数据的CSV文件存取 多维数据的存取 NumPy的随机数函数 NumPy的统计函数 NumPy的梯度函数

  6. Android Html处理器通用类 HtmlUtil

    1.整体分析 1.1.首先看一下源代码,可以直接Copy. public class HtmlUtil { /** * 获取 html 中的纯文本 */ public static String Ht ...

  7. [转]渗透测试tips...零碎的小知识

    1.拿到一个待检测的站,你觉得应该先做什么?收集信息whois.网站源IP.旁站.C段网站.服务器系统版本.容器版本.程序版本.数据库类型.二级域名.防火墙.维护者信息另说… 2.mysql的网站注入 ...

  8. getElementByName????????,????????,

    getElementByName可以获取多个元素,获得的是一个数组, getElementById只能获取一个,是dom从上往下的第一个元素.

  9. 程序员需要的各种PDF格式电子书【附网盘免费下载资源地址】

    程序员需要的各种PDF格式电子书[附网盘免费下载资源地址]   各位,请妥善保存,后期还会有更多更新,如果你有不同的书籍资源或者这里没有你要找的书籍,也可以直接留言,后期我们会继续更新~ Java & ...

  10. 《数据结构与算法分析:C语言描述》复习——第五章“堆”——二叉堆

    2014.06.15 22:14 简介: 堆是一种非常实用的数据结构,其中以二叉堆最为常用.二叉堆可以看作一棵完全二叉树,每个节点的键值都大于(小于)其子节点,但左右孩子之间不需要有序.我们关心的通常 ...