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 ...
随机推荐
- UVA - 1252 Twenty Questions (状压dp)
状压dp,用s表示已经询问过的特征,a表示W具有的特征. 当满足条件的物体只有一个的时候就不用再猜测了.对于满足条件的物体个数可以预处理出来 转移的时候应该枚举询问的k,因为实际上要猜的物品是不确定的 ...
- 上下文 xx
上下文,就是指在程序中的某个位置,可以访问到的所有资源的总和. 具体说来,在程序中资源可能是一个变量.一个常量.一个类的引用等等.
- 编写shellcode的几种姿势
今天开始在做hitcon-training的题目,做到lab2就发现了自己的知识盲区,遇到无法执行shell的情况,需要自己打shellcode执行cat flag 操作 经过一系列的搜索,发现了几种 ...
- laydate控件后台返回的时间前台格式化
//功能:laydate控件后台返回的时间前台格式化 //参数:laydate控件值 function formatDate(strTime) { if ("" === strTi ...
- Linux网卡设置为网桥模式
Linux网卡设置为网桥模式 1. 添加网卡,并修改相关配置文件 1.1虚拟机添加网卡,并配置相关文件 如:eth2为新添加网卡 cd /etc/sysconfig/network-script ...
- 【Java_基础】java中的多态性
方法的重载.重写和动态链接构成了java的多态性. 1.方法的重载 同一个类中多个同名但形参有所差异的方法,在调用时会根据参数的不同做出选择. 2.方法的重写 子类中重新定义了父类的方法,有关方法重写 ...
- netfilter 和 iptables
http://blog.chinaunix.net/uid/23069658/cid--1-list-4.html 洞悉linux下的Netfilter&iptables 系列,有一到十六, ...
- Re:从零开始的Linux之路(杂谈)
决定认真从零开始写一个Linux的学习过程,像我这么偷懒的人能写文字记录已经很不容易了,希望不要半途而废吧(拖走) 用多了Linux其实发现,要是哪天Linux和Windows能结合下就好了,简单粗暴 ...
- Action的实现方式
[Pojo方式] 1.概述 Pojo(Plain Ordinary Java Object)称为简单Java类,其实就是一个JavaBean. 2.示例 /** * Pojo类方式实现Action * ...
- luogu3231 [HNOI2013]消毒
前置技能:poj3041 如果是二维平面有一些方块,这些方块被染了黑色,你每次可以选择 \((x,y)\) 的区域染成白色,代价是 \(\min(x,y)\),问你付出的最小代价 显然我们不会这么染 ...