2014北京网络预选赛1006(贪心)HDU5037

来源:互联网 发布:linuxapp源码下线 编辑:程序博客网 时间:2022/01/17 07:02

Frog

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1357    Accepted Submission(s): 364


Problem Description
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.
 

Input
The 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.
 

Output
For 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
21 10 552 10 336
 

Sample Output
Case #1: 2Case #2: 4

题意:RT

思路:比较好的贪心题了

            每次只需要记录上一步跳的距离K

            然后如果现在可以调的距离为X,分两种情况

            如果X+K>=L+1,则可以往前跳X

            如果X+K<L+1,则要与上一步合并

            具体细节看代码吧,在纸上画一画就懂了

0 0
原创粉丝点击
热门问题 编写一个应用程序绘制一个如下的操作菜单并实现功能(定义一个类学生表示学生,有成员变量姓名name和年 手机是现在人们必不可少、最重要的通讯工具,拥有一款简单、实用、易用的手机通讯录,将会使你的手机更加好 手机是现在人们必不可少、最重要的通讯工具,拥有一款简单、实用、易用的手机通讯录,将会使你的手机更加好 编写一个应用程序绘制一个如下的操作菜单并实现功能(定义一个类学生表示学生,有成员变量姓名name和年 平坦衰落信道 平坦衰落信道2FSK差错性能分析 1204:剔除相关数 Minecraft 编写一个应用程序绘制一个如下的操作菜单并实现功能(定义一个类学生表示学生,有成员变量姓名name和年 2023 生产焦炭的上市公司 焦炭的热反应性 焦炭的工业分析 焦炭焦煤套利 石油焦与焦炭 焦炭出口代理 焦煤 焦炭 动力煤 焦煤与焦炭的区别 焦炭还原氧化铁 石油焦和焦炭 国际焦炭行情 完全燃烧42g焦炭 焦炭反应测定仪 焦炭检测设备 焦炭的挥发份 焦炭用于炼铁 冶金焦炭指标 石英砂与焦炭 焦炭筛分组成机械筛 2012年焦炭价格 焦炭冶炼金属 焦炭行业准入 全球焦炭产量 焦炭还原二氧化硅 焦炭和煤炭的区别 焦炭化验设备 焦炭还原氧化铁的化学方程式 焦炭的生产过程 焦炭和动力煤 焦炭还原氧化铜 焦炭耐磨强度 焦炭滤料价格 焦炭机械强度转鼓机 焦炭机械强度 焦炭生产工艺流程 焦炭的化学成分 焦炭燃烧温度 焦炭热反应强度 焦炭和煤的区别 焦炭机械强度测定转鼓 焦炭的化学式