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 ...
随机推荐
- Ngui使用随心记
Ngui的一些基础使用心得! BB:首先BB一下我觉得NGUI和UGUI哪个好?我首推UGUI,先不说是官方内置,在使用的方便性上也要好很多,而且NGUI停止更新了!还有就是NGUI有BUG! Ngu ...
- bash编程-条件测试
Shell脚本中经常需要判断某情况或者数据是否满足,需要由测试机制来实现. 测试方式 echo $?查看命令执行状态返回值 bash脚本中可以自定义返回值exit n(n为自己指定的状态码),shel ...
- extern的使用详解(多文件编程)——C语言
extern——关键字 extern是C语言中的一个关键字,一般用在变量名前或函数名前,作用是用来说明“此变量/函数是在别处定义的,要在此处引用”,extern这个关键字大部分读者应该是在变量的存储类 ...
- 移动端IM开发者必读(二):史上最全移动弱网络优化方法总结
1.前言 本文接上篇<移动端IM开发者必读(一):通俗易懂,理解移动网络的“弱”和“慢”>,关于移动网络的主要特性,在上篇中已进行过详细地阐述,本文将针对上篇中提到的特性,结合我们的实践经 ...
- shell if 条件判断
condition='123' if [ -z condition]; then echo "condition 是空的" fi 字符串判断: = 两个字符串相等. != 两个字符 ...
- java相关技术问答(一)
网上一些没有标准答案的面试题,我自己做的解答总结,有任何异议可以提出来~^_^,不断更新中... Springboot除了自动配置与传统的spring还有哪些不同 传统的springweb项目需要部署 ...
- 安装 composer 并启动 yii2 项目
环境 MacOS 10.12.6 PHP 5.6.30 yii2.0 一.composer (类似 node's npm) 1.安装 php -r "copy('https://getcom ...
- [译]ElasticSearch vs. Solr
在Gen2产品的早期阶段, 我们事实上是失败的, 这促使我们重新审视我们现有的技术栈. 我们仔细分析系统中的每个独立的组件,并记录下来, 当然其中也包括构成我们核心功能的搜索引擎技术. 在我们的通用日 ...
- OC学习4——OC新特性之块(Block)
文章主要参考 关于OC中的block自己的一些理解(一) 对块的深入理解 浅析ios开发中Block块语法的妙用 1.关于block block的作用:保存一段代码. 苹果官方推荐的一种语法,类似 ...
- 内存管理-slab[代码]
主要介绍kmalloc和kfree代码流程,侧重kmalloc和kfree流程中锁使用规则,会引用到cpuset,mempolicy(内存策略),numa相关知识.如果读起来比较困难可以参考另一篇随笔 ...