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. git 代码托管使用方法

    Git代码托管 1 准备材料 在coding,github这些代码托管网站上申请一个账户. Linux平台什么需要一个git,如ubuntu 需要 $ sudo apt-get install git ...

  2. PyQuery网页解析库

    from pyquery import PyQuery as pq 字符串初始化: doc = pq(html) URL初始化:doc = pq(url = "···") 文件初始 ...

  3. python爬虫-简单使用xpath下载图片

    首先 1.为方便以下进行 谷歌浏览器里要安装xpath脚本 2.下载一个lmxl     命令:pip install lxml 3. 以下三张图是一个,当时爬的 <糗事百科>里的图片 值 ...

  4. 单片机入门学习笔记8:STM32单片机使用

    经常会在某个QQ群里看见某人的QQ昵称的名字"不会32绝不改名",其实无论会不会,之后名称都改了. STM32单片机在我看来就三部分组成:各部分的初始化,中断的使用,Main函数内 ...

  5. Open source cryptocurrency exchange

    Peatio: https://github.com/peatio/peatio ViaBTC: https://github.com/viabtc/viabtc_exchange_server

  6. 笔记-scrapy-pipeline

    笔记-scrapy-pipeline 1.简介 scrapy抓取数据后,使用yield发送item对象至pipeline,pipeline顺序对item进行处理. 一般用于: 清洗,验证,检查数据: ...

  7. JavaSE——javac、javap、jad

    一.javac 用法:javac <选项> <源文件> 其中,可能的选项包括: -help                            帮助信息   -g       ...

  8. 1864: [Zjoi2006]三色二叉树

    1864: [Zjoi2006]三色二叉树 链接 分析: 做得最智障的一题了... 首先中间输出两个数之间没空格(换行居然也过了...), 写了dp[i][0/1/2],后来知道其实dp[i][0/1 ...

  9. ios tcpdump

    转载 前提条件:机器要破解,cydia能打开 需要工具1.openssh2.tcpdump 安装工具方法:1.连接网络,打开cydia2.确认Cydia设置为开发者模式(管理->设置->开 ...

  10. 《Cracking the Coding Interview》——第9章:递归和动态规划——题目7

    2014-03-20 03:35 题目:实现画图的Flood Fill操作. 解法:DFS和BFS皆可,但BFS使用的队列在时间复杂度上常数项比较大,速度略慢,所以我选了DFS.当然,如果图很大的话D ...