2014北京网络赛1006||hdu5037 思维题
来源:互联网 发布:c语言谭浩强电子版 编辑:程序博客网 时间:2024/03/28 16:48
http://acm.hdu.edu.cn/showproblem.php?pid=5037
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.
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.
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
21 10 552 10 336
Sample Output
Case #1: 2Case #2: 4
我参考:http://blog.csdn.net/u014569598/article/details/39471913
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;int n,m,l,a[200005];int main(){ int T,tt=0; scanf("%d",&T); while(T--) { scanf("%d%d%d",&n,&m,&l); for(int i=1;i<=n;i++) scanf("%d",&a[i]); a[0]=0;a[++n]=m; sort(a,a+n+1); int k=l; int ans=0; for(int i=1;i<=n;i++) { int x=(a[i]-a[i-1])%(l+1); int y=(a[i]-a[i-1])/(1+l); if(k+x>l) { ans+=2*y+1; k=x; } else { ans+=2*y; k+=x; } } printf("Case #%d: %d\n",++tt,ans); } return 0;}
0 0
- 2014北京网络赛1006||hdu5037 思维题
- 2014北京网络预选赛1006(贪心)HDU5037
- [2014 北京网络赛]
- 2017北京网络赛 hihocoder 1580 Matrix (dp很好的思维题)
- hihocoder1586-2017acm北京网络赛9&线段树&思维&板子- Minimum
- HDU 5036 Explosion 2014 北京网络赛E题
- icpc 北京网络赛 1006 贪心算法
- 2014北京网络赛1007||hdu5038 模拟
- 套题总结:2011北京网络赛
- 2015北京赛区网络赛模拟题
- hihoCoder1228(2015北京网络赛B题)
- hihoCoder1233(2015北京网络赛H题)
- 15北京网络赛 B题
- 15北京网络赛 E题
- hiho1385 -- 模拟题(2016北京网络赛)
- hiho1385 -- 模拟题(2016北京网络赛)
- 北京网络赛
- 2017北京网络赛
- iOS应用审核的时隐私政策模板
- ON_NOTIFY
- img 等比例缩放
- 提高用户体验--子非鱼,须知鱼之乐
- PLSQL学习教程(全)
- 2014北京网络赛1006||hdu5037 思维题
- 使用MFC 发送消息模拟按钮按下事件
- 安全运维之:Linux后门入侵检测工具的使用
- ubuntu下提交代码 git commit -a 将编辑器默认的nano改为vim
- 时尚型男怎样选择一款适合自己的香水
- ld时静态库的顺序
- NSLayoutConstraint
- vimrc配置文件
- UVa - 11136 Hoax or what (水题 最大最小堆 set)