HDU5037 贪心
来源:互联网 发布:知行理工初始密码 编辑:程序博客网 时间:2024/04/23 18:45
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
这破贪心我做了俩小时….
看着感觉是水题掉以轻心….
结果被狠狠地教做人了………..
一开始还没读懂题…
后来才知道他给的是必须走的…
先知道最小周期最大步数是怎么个走法….
因为设定这个人聪明所以他一步肯定想走L…
但是不能让他走l…
所以给他一步放一个,L步放一个…
这样l+1的周期里就有俩了…
然后模一遍看看剩下多少就好了…
要是有剩余就和上一次剩下的加在一起看看够不够L
不够的话就只能下次再说了…
要是够了的话走一步,一开始初始化为L是为了第一次走,那玩意一定剩不下………给他一个站的位置
不然还要特判很麻烦
#include<iostream>#include<queue>#include<algorithm>#include<cstdio>#include<memory.h>#include<string>using namespace std;int tu[1500000];int main(){ int T; cin >> T; int u = 0; while (T--) { int n, m, l; cin >> n >> m >> l; for (int a = 1;a <= n;a++)scanf("%d", &tu[a]); tu[++n] = m; tu[0] = 0; int xianzai = l; long long sum = 0; sort(tu, tu + n); for (int a = 0;a < n;a++) { int cha = tu[a + 1] - tu[a]; int bu = cha /(l+1); bu *= 2; int shengyu = cha%(l+1); if (shengyu + xianzai > l) { xianzai = shengyu; sum++; sum += bu; } else { xianzai += shengyu; sum += bu; } } printf("Case #%d: %lld\n", ++u, sum); } return 0;}
- hdu5037(贪心)
- HDU5037 贪心
- hdu5037 Frog 贪心
- HDU5037 frog贪心
- hdu5037 Frog --- 贪心
- hdu5037 Frog --- 贪心
- HDU5037-贪心(很好)-Frog
- 2014北京网络预选赛1006(贪心)HDU5037
- 2014北京网络赛1006||hdu5037 思维题
- 贪心!
- 贪心~
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- 贪心
- UOJ#127. 【NOI2015】程序自动分析
- VLC 推流的简单设置
- C++中,两个头文件互相引用怎么办
- load Sdk stackflow.md
- Leetcode-92. Reverse Linked List II
- HDU5037 贪心
- 深入理解HTTP Session
- unity Physics.Raycast 函数 LayerMask用法测试
- delphi label 背景颜色设置!
- 在SpringMVC中使用@RequestBody注解处理json时,报出HTTP Status 415的解决方案
- 你必须了解的Session的本质
- 数据库基本语法
- Winform 数据库连接app.config文件配置 数据库连接字符串
- 学习笔记-----关于VS中使用模板类出现无法解析的外部符号问题