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 ...
随机推荐
- UVA1515 Pool construction (最小割模型)
如果不允许转化'#'和'.'的话,那么可以直接在'#'和'.'之间连容量为b的边,把所有'#'和一个源点连接, 所有'.'和一个汇点连接,流量不限,那么割就是建围栏(分割'#'和'.')的花费. 问题 ...
- k8s 如何 Failover?
上一节我们有 3 个 nginx 副本分别运行在 k8s-node1 和 k8s-node2 上.现在模拟 k8s-node2 故障,关闭该节点. 等待一段时间,Kubernetes 会检查到 k8s ...
- nyoj-915—— +-字符串
http://acm.nyist.net/JudgeOnline/problem.php?pid=915 +-字符串 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 Sh ...
- 给 MSYS2 添加国内源
https://wiki.qt.io/MSYS2pacman -S base-devel git mercurial svn wget p7zip软件包 开发包 http://mirrors.ustc ...
- PAT (Basic Level) Practise (中文)-1028. 人口普查(20)
PAT (Basic Level) Practise (中文)-1028. 人口普查(20) http://www.patest.cn/contests/pat-b-practise/1028 某 ...
- webuploader项目中多图片上传实例
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- shell脚本,如何破解字符串对应的md5sum前的RANDOM对应数字?
已知下面的字符串是通过RANDOM随机数变量md5sum|cut-c 1-8截取后的结果,请破解这些字符串对应的md5sum前的RANDOM对应数字?[root@localhost md5]# cat ...
- ios之UISlider
初始化一个Slider UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(0, 400,320 , 20)]; 滑块是一个标 ...
- [LUOGU]P1443 马的遍历
题目描述 有一个n*m的棋盘(1< n,m<=400),在某个点上有一个马,要求你计算出马到达棋盘上任意一个点最少要走几步 输入输出格式 输入格式: 一行四个数据,棋盘的大小和马的坐标 输 ...
- 【OS_Linux】Linux中虚拟机的三种上网方式——桥接、NAT、Host-only
1.桥接 桥接方便做实验,配置ip方便.可以和局域网中的其他机器进行通信,也可以和公网进行通信.缺点是会占用主机所在局域网的一个ip. 2. NAT NAT模式下虚拟机可以和主机进行通信,可以上网,而 ...