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. request中的那些方法到底是干什么的?

    最近做Java Web项目,在.jsp页面和servlet之间request和response还是有些混淆,查阅了一些资料,总结如下,方便以后使用: 首先,servlet接口是最基本的,提供的五个方法 ...

  2. python分布式爬虫--房天下

    第一步安装redis redis在windows系统中的安装与启动: 下载:redis官方是不支持windows操作系统的.但是微软的开源部门将redis移植到了windows上.因此下载地址不是在r ...

  3. POJ:3185-The Water Bowls(枚举反转)

    The Water Bowls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7402 Accepted: 2927 Descr ...

  4. rpm、yum命令

    一.rpm命令 挂载光盘文件到/media目录: 进去/media目录下的Packages目录: 查看系统已安装的所有rpm包: 查看系统是否安装dhcp软件包: 安装dhcp软件包: 查看dhcp软 ...

  5. 奇异值分解(SVD)原理详解及推导

    在网上看到有很多文章介绍SVD的,讲的也都不错,但是感觉还是有需要补充的,特别是关于矩阵和映射之间的对应关系.前段时间看了国外的一篇文章,叫A Singularly Valuable Decompos ...

  6. 9path 导致的一场冤假错案

    今天做对话框开发,遇到一个问题,就是弹出来的对话框太丑了.如图: 大家都是warp_content, 前面几个就是真的wrap_coment了.只有最后一个还可以看.后来自己找代码,写的都一样,就去问 ...

  7. android 事件拦截 (Viewpager不可以左右滑动)

    以前没有做过真正的需求,所以从来没有觉得事件拦截分发处理有什么好懂的. 现在做需求了,真的是什么需求都有,你作为开发都要去研究实现.比如说,只能点不能滑动的viewpager.其实这都可以不用view ...

  8. jQuery上传文件控件Uploadify使用

    Uploadify是JQuery的一个上传插件,支持ajax无刷新上传,多个文件同时上传,上传进行进度显示,删除已上传文件等. 首先应下载jQuery和uploadify插件 jQuery下载地址:h ...

  9. JQuery方法总结

    JQuery方法总结 Dom: Attribute:(属性) $("p").addClass(css中定义的样式类型); 给某个元素添加样式 $("img"). ...

  10. Selenium+Python自动化之如何绕过登录验证码

    一.使用Fiddler抓包 1.一般登陆网站成功后,会生成一个已登录状态的cookie,那么只需要直接把这个值拿到,用selenium进行addCookie操作即可. 2.可以先手动登录一次,然后抓取 ...