Frog

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

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

2
1 10 5
5
2 10 3
3
6
 

Sample Output

Case #1: 2
Case #2: 4
 

Source

 
 //2017-10-08
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm> using namespace std; const int N = ;
int arr[N], n, m, l, ans, T; int main(){
int kase = ;
scanf("%d", &T);
while(T--){
scanf("%d%d%d", &n, &m, &l);
arr[] = ;
arr[n+] = m;
for(int i = ; i <= n; i++)
scanf("%d", &arr[i]);
sort(arr, arr+n+);
ans = ;
int k = l;
for(int i = ; i <= n+; i++){
int a = (arr[i]-arr[i-])%(l+);
int b = (arr[i]-arr[i-])/(l+);
if(a+k >= l+){
k = a;
ans += *b+;
}else{
k += a;
ans += *b;
}
}
cout<<"Case #"<<++kase<<": "<<ans<<endl;
} return ;
}

HDU5037(SummerTrainingDay01-C)的更多相关文章

  1. hdu5037 Frog (贪心)

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

  2. 【数学,方差运用,暴力求解】hdu-5037 Galaxy (2014鞍山现场)

    话说这题读起来真费劲啊,估计很多人做不出来就是因为题读不懂...... 从题目中提取的几点关键点: 题目背景就是银河系(Rho Galaxy)中的星球都是绕着他们的质心(center of mass) ...

  3. HDU5037 Frog

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

随机推荐

  1. MongoDB、MySQL

    我的电脑的系统Path:   D:\sqlite;D:\Program Files\MongoDB\Server\3.4\bin;%MYSQL_HOME%\bin;D:\Program Files\B ...

  2. Struts2下载及简介

    Struts2下载及简介 一.Struts2下载: 进入网址:http://struts.apache.org/download.cgi#struts23163 可以下载最新的Struts2. 1.F ...

  3. B - Dropping tests

    In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cum ...

  4. MySQL DDL--ghost执行模板和参数

    常用GHOST模板 ##================================================## mysql_ip="127.0.0.1" mysql_ ...

  5. vs2008快捷键一览表

    Ctrl+E,D ----             格式化全部代码 Ctrl+K,F ----             格式化选中的代码 CTRL + SHIFT + B          生成解决方 ...

  6. es2017新特性

    2017年6月底es2017不期而至; 截止目前es8是ecmascript规范的第九个版本:自es2015开始ECMA协会将每年发布一个版本并将年号作为版本号:算了 直接看下es2017的新特性: ...

  7. HashMap的源码分析

    hashMap的底层实现是 数组+链表 的数据结构,数组是一个Entry<K,V>[] 的键值对对象数组,在数组的每个索引上存储的是包含Entry的节点对象,每个Entry对象是一个单链表 ...

  8. Vue2.0+组件库总结

    转自:https://blog.csdn.net/lishanleilixin/article/details/84025459 UI组件 element - 饿了么出品的Vue2的web UI工具套 ...

  9. 物体检测,Error: maximum box coordinate value is too large

    使用ssd目标检测,出现error:maximum box coordinate value is larger than 1.100000: ] [1.325] 主要原因在于,用labelImg 标 ...

  10. Mybatis-generator生成Service和Controller

    好久记录笔记,这段时间做政府的项目,数据录入系统基本都是通过excel导入,且数据量大,许多也是单表的录入,这就有很多可以通用的代码,如controller,service层的那一套都是可以代码生成, ...