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 ...
随机推荐
- verilog HDL -模块代码基本结构
1--verilog HDL 语言的预编译指令作用:指示在编译verliog HDL源代码前,需要执行哪些操作. 2--模块内容是嵌在module 和endmodule两个语句之间.每个模块实现特定的 ...
- faster-RCNN台标检测
最近学习了faster-RCNN算法,收获不少,记此文为证.faster-RCNN是一个目标检测算法,它能够识别多个目标,对目标分类并标注位置,非常好用.它的输入样本是标注好的图片,输出是一个hdf5 ...
- Oracle服务器和客户端安装在同一台机器的情况
最近重装了系统,所有的开发环境需要重新部署一下,因此重新安装了Oracle,结果原来没有问题,这一次又碰到了几个问题(tns12154和tns03505),让我好一搞啊.不过又重新对Oracle加深了 ...
- unity 简单通用游戏模式设计
好吧好吧,又谈到这个问题了,其实早就想写这个博客了,犹豫了好久.在设计游戏的时候我本人是很排斥什么游戏架构设计,mvc什么的,我只想马上动手就把自己的游戏玩法最快的用代码敲出来,还不会出无法挽回的错误 ...
- 由百度 “PHP薪资” 引发的思考
昨天晚上睡觉的时候百度了一下 “PHP薪资”,看到了各种各样的答案,从百度知道到知乎,再到各个论坛……答案也是从 2k-16k 不等(不过说实话,2k是吓到我了),其中一些答案说到了在中国从事某一行业 ...
- Eclipse 工作空间的相关说明
工作空间文件说明 当eclipse选定一个文件夹作为workspace工作空间时,就会在该目录中生成一些文件. 共三个文件夹:.metadata ..recommenders .RemoteSyste ...
- Maven 的安装与配置
最近公司需要新起一个项目,想使用maven+springmvc+spring+mybatis+mysql实现,以前我们的项目都是传统的老项目,没用过maven,Eclipse版本是GALILEO的,有 ...
- struts2框架学习笔记3:获取servletAPI
Struts2存在一个对象ActionContext(本质是Map),可以获得原生的request,response,ServletContext 还可以获得四大域对象(Map),以及param参数( ...
- Linux - 多窗口管理器Screen程序
GNU's Screen homepage Screen是由GNU计划开发的用于命令行终端切换的自由软件,可以看作是窗口管理器的命令行界面版本. 可以通过该软件同时连接多个本地或远程的命令行会话,并在 ...
- linux中一些简便的命令之tr
tr是个简单字符处理命令,主要有以下几个用法: 1.替换字符: echo "hello,world" | tr 'a-z' 'A-Z' 执行结果:HELLO,WORLD 注释:这里 ...