博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 5037 Frog 贪心 dp
阅读量:7303 次
发布时间:2019-06-30

本文共 2772 字,大约阅读时间需要 9 分钟。

哎,注意细节啊,,,,,,,思维的严密性。。。。。

 

 

11699193 2014-09-22 08:46:42 Accepted 796MS 1864K G++

Frog

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 454    Accepted Submission(s): 96

Problem Description
   Once upon a time, there is a little frog called Matt. One day, he came to a river.
   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.
 
Input
   The first line contains only one integer T, which indicates the number of test cases.
   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.
 
Output
   For each test case, just output one line “Case #x: y", where x is the case number (starting from 1) and y is the maximal number of steps Matt should jump.
 
Sample Input
2 1 10 5 5 2 10 3 3 6
 
Sample Output
Case #1: 2 Case #2: 4
 
Source
 
Recommend
hujie   |   We have carefully selected several similar problems for you:            

 

 

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 11 #define N 200005 12 #define M 15 13 #define mod 10000007 14 //#define p 10000007 15 #define mod2 100000000 16 #define ll long long 17 #define LL long long 18 #define maxi(a,b) (a)>(b)? (a) : (b) 19 #define mini(a,b) (a)<(b)? (a) : (b) 20 21 using namespace std; 22 23 int T; 24 int n; 25 int m,l; 26 int dp[N]; 27 int p[N]; 28 29 void ini() 30 { 31 memset(dp,0,sizeof(dp)); 32 scanf("%d%d%d",&n,&m,&l); 33 for(int i=1;i<=n;i++){ 34 scanf("%d",&p[i]); 35 } 36 sort(p+1,p+1+n); 37 p[n+1]=m; 38 } 39 40 41 void solve() 42 { 43 int sh; 44 int te; 45 int now; 46 int end; 47 int d; 48 int tnow; 49 now=0; 50 d=1; 51 for(int i=1;i<=n+1;){ 52 dp[i]=dp[i-1]; 53 te=(p[i]-now); 54 sh=te/(l+1); 55 dp[i]+=sh*2+1; 56 if(te%(l+1)!=0){ 57 //dp[i]--; 58 // if(sh!=0 && te%(l+1)

 

转载于:https://www.cnblogs.com/njczy2010/p/3985370.html

你可能感兴趣的文章
Spring Boot + Websocket + Thymeleaf + Lombok
查看>>
linux命令之uniq
查看>>
SugarCRM 插件介绍
查看>>
aliyun.com
查看>>
cygwin的使用(2)
查看>>
App域名劫持之DNS高可用 - 开源版HttpDNS方案详解(转)
查看>>
Install Oracle 11gR2 on Debian wheezy(转)
查看>>
将若干字符串按字母顺序(由小到大)输出(用指针)
查看>>
PostgreSQL 如何快速构建 海量 逼真 测试数据
查看>>
【错误解决】[Maven]使用Maven配置Jstl出现异常:The absolute uri: http://java.sun.com/jsp/jstl/core cannot......
查看>>
linux命令之touch
查看>>
Content://sms
查看>>
估算之痛
查看>>
[20171206]rman与truncate2.txt
查看>>
谈消息总线的路由模型
查看>>
结构体中指针赋值问题的分析及C代码示例
查看>>
java并发编程学习:如何等待多个线程执行完成后再继续后续处理(synchronized、join、FutureTask、CyclicBarrier)...
查看>>
TortoiseGit配合msysGit在Git@OSC代码托管的傻瓜教程
查看>>
边缘计算“CROSS”欧洲新战场
查看>>
WeUI—微信官方UI库
查看>>