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 ...
随机推荐
- 第1节 flume:11、flume的failover机制实现高可用
1.4 高可用Flum-NG配置案例failover 在完成单点的Flume NG搭建后,下面我们搭建一个高可用的Flume NG集群,架构图如下所示: 图中,我们可以看出,Flume的存储可以支持多 ...
- servlet上传多个文件(乱码解决)
首先,建议将编码设置为GB2312,并在WEB-INF\lib里导入:commons-fileupload-1.3.jar和commons-io-2.4.jar, 可百度下下载,然后你编码完成后,上传 ...
- shell脚本,用awk实现替换文件里面的内容。
文件是这样,有ID和具体信息,ID行以@开头,后面的信息有空格,把第一个空格后的全部内容替换为空格前的字符. 用AWK来实现. @AA10 P 7 #YYYYYYYYYYYYYYYYYYZZZZZZZ ...
- 人脸识别中的检测(在Opencv中加入了QT)
#include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include & ...
- 连接器前置挂载U盾
连接器前置挂载U盾 1. 宿主机配置及其信息 虚拟化软件版本 主机名 宿主机IP 账号及其密码 WorkStation windows idca- vm01 172.16.6.30 * Qemu-kv ...
- 74个Swift标准库函数
74个Swift标准库函数 本文译自 Swift Standard Library: Documented and undocumented built-in functions in the Swi ...
- xhEditor编辑器上传图片到 OSS
前段时间,公司在项目上用到了xhEditor编辑器来给用户做一个上传图片的功能当时做的时候觉得很有意思,想想 基本的用户图片上传到自己服务器,还有点小占地方: 后来....然后直接上传到阿里云 .接下 ...
- Python自动化测试框架——数据驱动(从代码中读取)
今天小编要介绍的是数据驱动最简单和最常用的一种方法,由于只是介绍方法,代码操作后的美观程度略有缺陷,介意者可以自行改动 还是以163邮箱登录为例: 设计一个存放数据的类,这个类的参数是我们需要修改的数 ...
- 对于js运动中产生的问题
1.不同的对象调用同一个定时器情况,则需要将定时器的名称定为该对象的一个属性来进行运用. 例: <!DOCTYPE html> <html lang="en"&g ...
- Mining of Massive Datasets-1
given lots of data->discover patterns and models that are: valid, useful, unexpected, understanda ...