hdu 5037 Frog 贪心 dp
哎,注意细节啊,,,,,,,思维的严密性。。。。。
11699193 | 2014-09-22 08:46:42 | Accepted | 5037 | 796MS | 1864K | 2204 B | G++ | czy |
Frog
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 454 Accepted Submission(s): 96
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.
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.
1 10 5
5
2 10 3
3
6
Case #2: 4
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<string> #define N 200005
#define M 15
#define mod 10000007
//#define p 10000007
#define mod2 100000000
#define ll long long
#define LL long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int T;
int n;
int m,l;
int dp[N];
int p[N]; void ini()
{
memset(dp,,sizeof(dp));
scanf("%d%d%d",&n,&m,&l);
for(int i=;i<=n;i++){
scanf("%d",&p[i]);
}
sort(p+,p++n);
p[n+]=m;
} void solve()
{
int sh;
int te;
int now;
int end;
int d;
int tnow;
now=;
d=;
for(int i=;i<=n+;){
dp[i]=dp[i-];
te=(p[i]-now);
sh=te/(l+);
dp[i]+=sh*+;
if(te%(l+)!=){
//dp[i]--;
// if(sh!=0 && te%(l+1)<d){
// dp[i]--;
// tnow=now+(sh-1)*(l+1)+d;
// end=tnow+l;
// now=p[i]; // }
// else{
now=now+sh*(l+);
tnow=now;
end=tnow+l;
now=p[i];
// } i++;
while(i<=n+ && p[i]<=end){
dp[i]=dp[i-];
now=p[i];
i++;
}
d=l+-(now-tnow);
}
else{
dp[i]--;
tnow=now+(sh-)*(l+)+d;
end=tnow+l;
now=p[i];
i++;
while(i<=n+ && p[i]<=end){
dp[i]=dp[i-];
now=p[i];
i++;
}
d=l+-(now-tnow);
}
}
} void out()
{
printf("%d\n",dp[n+]);
} int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
scanf("%d",&T);
for(int cnt=;cnt<=T;cnt++)
// while(T--)
// while(scanf("%d%d",&n,&m)!=EOF)
{
// if(n==0 && m==0) break;
printf("Case #%d: ",cnt);
ini();
solve();
out();
} return ;
}
hdu 5037 Frog 贪心 dp的更多相关文章
- HDU 5037 Frog(贪心)
题意比较难懂,一只青蛙过河,它最多一次跳L米,现在河中有石头,距离不等,上帝可以往里加石头,青蛙非常聪明,它一定会选择跳的次数最少的路径.问怎么添加石头能让青蛙最多的次数.输出青蛙跳的最多的次数. 考 ...
- hdu 5037 Frog(贪心)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5037 题解:为了让放的石头有意义肯定是没l+1的距离放2个也就是说假设现在位置为pos那么 ...
- HDU 5037 Frog(2014年北京网络赛 F 贪心)
开始就觉得有思路,结果越敲越麻烦... 题意很简单,就是说一个青蛙从0点跳到m点,最多可以跳l的长度,原有石头n个(都仅表示一个点).但是可能跳不过去,所以你是上帝,可以随便在哪儿添加石头,你的策略 ...
- HDU 5037 FROG (贪婪)
Problem Description Once upon a time, there is a little frog called Matt. One day, he came to a rive ...
- hdu 2128 Frog(简单DP)
Frog Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
- hdu 1257 最少拦截系统【贪心 || DP——LIS】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- 【BZOJ-3174】拯救小矮人 贪心 + DP
3174: [Tjoi2013]拯救小矮人 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 686 Solved: 357[Submit][Status ...
- HDU 1011 树形背包(DP) Starship Troopers
题目链接: HDU 1011 树形背包(DP) Starship Troopers 题意: 地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...
- hdu 2296 aC自动机+dp(得到价值最大的字符串)
Ring Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
随机推荐
- js获取当前日期、前一天、后一天的日期的例子
<script> function addByTransDate(dateParameter, num) { var translateDate = "", dateS ...
- nyoj-47-过河问题|POJ-1700-Crossing River
http://acm.nyist.net/JudgeOnline/problem.php?pid=47 http://poj.org/problem?id=1700 解题思路:求最少需要多少时间才能都 ...
- PAT (Basic Level) Practise (中文)- 1026. 程序运行时间(15)
PAT (Basic Level) Practise (中文)- 1026. 程序运行时间(15) http://www.patest.cn/contests/pat-b-practise/10 ...
- 二. python函数与模块
第四章.内置函数与装饰器详解 1.内置函数补充1 注:红色圆圈:必会: 紫红色方框:熟练: 绿色:了解 callable() 判断函数是否可以被调用执行 def f1(): pass f1() ...
- Dev-Cpp 5.11 c++编译器下载
Dev-Cpp 5.11 c++编译器下载地址: 链接: https://pan.baidu.com/s/1jHMAf1k 密码: i6nw
- clover如何使用UEFI引导和EFI驱动选择
EFI分区实际上是一个FAT格式的分区,不一定要是第一个分区,GPT磁盘下任何一个FAT文件格式的分区都可以用来放EFI引导文件.主板UEFI先默认引导你所设置的第一优先启动分区下的\EFI\boot ...
- 17条 Swift 最佳实践规范
本文由CocoaChina译者小袋子(博客)翻译自schwa的github主页原文作者:schwa 这是一篇 Swift 软件开发的最佳实践教程. 前言 这篇文章是我根据在 SwiftGraphics ...
- C语言:哲学家吃饭问题
//五个哲学家围坐在一起,两人之间都放有一个叉子,意大利面需要2个叉子吃,哲学家吃饭时候叉子只能拿左右手,哲学家除了吃饭时间其他时间都在思考 #include <stdio.h> #inc ...
- js的弹性运动
弹性: 速度+=(目标点-当前值)/系数://系数大概可以选择6,7,8 速度*=摩擦系数://系数可以选择0.7,0.75,0.8 缓冲: 速度=(目标点-当前值)/系数: 速度取整:
- 【php】 布尔值判断
当转换为 boolean 时,以下值被认为是 FALSE: 布尔值 FALSE 本身 整型值 0(零) 浮点型值 0.0(零) 空字符串,以及字符串 "0" 不包括任何元素的数组 ...