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 ...
随机推荐
- @ConditionalOnProperty来控制Configuration是否生效
1. 简介 Spring Boot通过@ConditionalOnProperty来控制Configuration是否生效 2. 说明 @Retention(RetentionPolicy.RUNTI ...
- python_112_网络编程 Socket编程
实例1:客户端发小写英文,服务器端返回给客户端大写英文(仅支持一次接受发送) 服务器端: #服务器端(先于客户端运行) import socket server=socket.socket() ser ...
- shell脚本,tee小工具的用法。
解释: tee是个工具 , 它的作用就是把标准输出,复制一份,扔文件里 ,原标准输出还输出,-a就相当于 >> 追加到文件里的意思. 不加就是 > 重定向到文件里去.
- ios之UILabel
详细使用: UILabel *label = [[UILabelalloc] initWithFrame:CGRectMake(0, 0, 75, 40)]; //声明UIlbel并指定其位置和长 ...
- Codeforces Round #510 #C Array Product
http://codeforces.com/contest/1042/problem/C 给你一个有n个元素序列,有两个操作:1,选取a[i]和a[j],删除a[i],将$a[i]*a[j]$赋值给a ...
- vba练习资料
链接:https://pan.baidu.com/s/1E0e58rZ_3QCCorWNM-ehSA 提取码:jluf
- (45)zabbix报警媒介:SMS
介绍 服务器安装串口GSM短信猫之后,zabbix可以使用它来发送短信通知给管理员,如下注意事项: 串行设备速度要与GSM猫相匹配(linux下默认为/dev/ttyS0),zabbix无法设置设置串 ...
- Linux基础学习-Docker学习笔记
Docker安装 1 官方网站访问速度很慢,帮助文档 2 国内中文网站,帮助文档 [root@qdlinux ~]# yum remove docker \ docker-client \ docke ...
- PHP方法之 substr
简单描述: substr 主要用于字符串的截取,但是不适用于中文字符串,易出现乱码,中文字符串可使用mbstring. 方法申明: substr(string,start,length) string ...
- aggregate和annotate使用
aggregate和annotate方法的使用场景 Django的aggregate和annotate方法属于高级查询方法,主要用于组合查询,是Django高手们必需要熟练掌握的.当我们需要对查询集( ...