HDU5037(SummerTrainingDay01-C)
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
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
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
Sample Input
Sample Output
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)的更多相关文章
- hdu5037 Frog (贪心)
http://acm.hdu.edu.cn/showproblem.php?pid=5037 网络赛 北京 比较难的题 Frog Time Limit: 3000/1500 MS (Java/Othe ...
- 【数学,方差运用,暴力求解】hdu-5037 Galaxy (2014鞍山现场)
话说这题读起来真费劲啊,估计很多人做不出来就是因为题读不懂...... 从题目中提取的几点关键点: 题目背景就是银河系(Rho Galaxy)中的星球都是绕着他们的质心(center of mass) ...
- HDU5037 Frog
Once upon a time, there is a little frog called Matt. One day, he came to a river. The river could b ...
随机推荐
- yum-Remi源配置
Remi repository 是包含最新版本 PHP 和 MySQL 包的 Linux 源,由 Remi 提供维护. 有个这个源之后,使用 YUM 安装或更新 PHP.MySQL.phpMyAdmi ...
- 三种定义bean的方式
方法一:基于XML的bean定义(需要提供setter方法) 1.首先编写student.java和teacher.java两个类 Student.java: public class Student ...
- Netty 发送消息失败或者接收消息失败的可能原因
1. 消息发送失败: 检查通道是否建立成功 Netty中的通道建立采用的是异步方式,获取到的通道对象可能为空或初始化未完成: 2. 接收的消息有丢失 消息可能会粘包,是否有拆包机制
- 在Shell脚本中获取指定进程的PID
注意这条命令用反引号(Tab上面的那个键)括起来,作用类似于${ } processId = ` ps -ef | grep fms.jar | grep -v grep | awk '{print ...
- Taglist: Exuberant ctags (http://ctags.sf.net) not found in PATH. Plugin is not loaded
1 开发环境 Ubuntu16.04(64bit) 2 错误描述 安装好Vim的TagList插件后,打开Vim提示: 3 解决方法 根据参考资料[1]的提示,可知那是因为当前系统没有安装ctags导 ...
- Servlet-转发和重定向的区别
实际发生位置不同,地址栏不同 转发是发生在服务器上的 转发是由服务器进行跳转的,细心的朋友会发现,在转发的时候,浏览器的地址栏是没有发生变化的,在我访问Servlet111的时候,即使跳转到了Serv ...
- 【xsy2304】哈 最短路
题目大意:有一个$n$个点,$m$条有向边的图,有$q$组询问. 每次询问:从$a$到$b$,经过不超过$c$条边,且依次经过的边边权递增,问最短路为多少,无解输出-1. 数据范围:$n≤150$,$ ...
- [Umbraco] umbraco中如何分页
分页功能应该说是web开发中最基本的功能了,常规的做法是通过查询sql语句进行分页数据显示.但在umbraco中却不是这样子的.而且通过xpath中的postion来定位.如下代码 <?xml ...
- 高性能、高可用性Socket通讯库介绍 - 采用完成端口、历时多年调优!(附文件传输程序)
前言 本人从事编程开发十余年,因为工作关系,很早就接触socket通讯编程.常言道:人在压力下,才可能出非凡的成果.我从事的几个项目都涉及到通讯,为我研究通讯提供了平台,也带来了动力.处理socket ...
- QMessageBox的使用
/** 使用非静态API,属性设置API **/ QMessageBox msgBox; msgBox.setWindowTitle("Note");/** 设置标题 **/ ms ...