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

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

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
2014 ACM/ICPC Asia Regional Beijing Online
Recommend
hujie   |   We have carefully selected several similar problems for you:  5041 5040 5039 5038 5036 
  1 #include<iostream>
  2 #include<cstring>
  3 #include<cstdlib>
  4 #include<cstdio>
  5 #include<algorithm>
  6 #include<cmath>
  7 #include<queue>
  8 #include<map>
  9 #include<string>
 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)<d){
 59                // dp[i]--;
 60                // tnow=now+(sh-1)*(l+1)+d;
 61                // end=tnow+l;
 62                // now=p[i];
 63
 64            // }
 65            // else{ 66                 now=now+sh*(l+1);
 67                 tnow=now;
 68                 end=tnow+l;
 69                 now=p[i];
 70            // }
 71
 72             i++;
 73             while(i<=n+1 && p[i]<=end){
 74                 dp[i]=dp[i-1];
 75                 now=p[i];
 76                 i++;
 77             }
 78             d=l+1-(now-tnow);
 79         }
 80         else{
 81             dp[i]--;
 82             tnow=now+(sh-1)*(l+1)+d;
 83             end=tnow+l;
 84             now=p[i];
 85             i++;
 86             while(i<=n+1 && p[i]<=end){
 87                 dp[i]=dp[i-1];
 88                 now=p[i];
 89                 i++;
 90             }
 91             d=l+1-(now-tnow);
 92         }
 93     }
 94 }
 95
 96 void out()
 97 {
 98     printf("%d\n",dp[n+1]);
 99 }
100
101 int main()
102 {
103     //freopen("data.in","r",stdin);
104     //freopen("data.out","w",stdout);
105     scanf("%d",&T);
106     for(int cnt=1;cnt<=T;cnt++)
107    // while(T--)
108    // while(scanf("%d%d",&n,&m)!=EOF)
109     {
110       //  if(n==0 && m==0) break;
111         printf("Case #%d: ",cnt);
112         ini();
113         solve();
114         out();
115     }
116
117     return 0;
118 }

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

hdu 5037 Frog 贪心 dp相关推荐

  1. hdu 5037 Frog(贪心)

    题意:有一只青蛙想从0点跳到M点.从0点到M点有N块石头,给出你N块石头的位置.青蛙跳跃的长度为0~L.你上帝,当青蛙无法跳跃的时候你可以帮助它. 可以无限制的在池塘内任何一点添加石头,并且你是仁慈的 ...

  2. HDU 5037 Frog(2014年北京网络赛 F 贪心)

    开始就觉得有思路,结果越敲越麻烦...  题意很简单,就是说一个青蛙从0点跳到m点,最多可以跳l的长度,原有石头n个(都仅表示一个点).但是可能跳不过去,所以你是上帝,可以随便在哪儿添加石头,你的策略 ...

  3. HDU 5037 Frog

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5037 题意:一只青蛙从0跳到m,最远能跳l,只能在石头上跳.给出一开始n个石头的位置,我们是上帝,能放 ...

  4. URAL 1203 Scientific Conference(贪心 || DP)

    Scientific Conference 之前一直在刷计算几何,邀请赛连计算几何的毛都买见着,暑假这一段时间就做多校,补多校的题目,刷一下一直薄弱的DP.多校如果有计算几何一定要干掉-.- 题意:给 ...

  5. Codeforces Round #699 (Div. 2) E.Sorting Books(贪心+DP / 线段树)超高质量题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 E - Sorting Books 一排书架上有 nnn 本书排成一排,每本书上有一个颜色 aia_i ...

  6. 【bzoj3174】[Tjoi2013]拯救小矮人 贪心+dp

    题目描述 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀上,知道最顶端的小矮人伸直胳膊可以碰到陷阱口.对于每一个小矮人,我们知道他从脚 ...

  7. HDU 4001 To Miss Our Children Time(2011年大连网络赛 A 贪心+dp)

    开始还觉得是贪心呢...  给你三类积木叫你叠楼房,给你的每个积木包括四个值:长 宽(可以互换) 高 类型d  d=0:你只能把它放在地上或者放在 长 宽 小于等于 自己的积木上面  d=1:你只能把 ...

  8. HDU - 5242 Game(树形dp+树链剖分/树上贪心+思维)

    题目链接:点击查看 题目大意:给出一棵包含n个节点的树,每个节点都有一个权值,整棵树的根是点1,问从点1开始向下一直走到叶子节点,可以走k次,怎么样走权值和最大,每个节点被走过一次后权值会变为0 题目 ...

  9. HDU 2546 饭卡(贪心+DP)

    题目链接 几个月之前做的一个题了,开始想时就看出应该是个01背包问题,又发现不太一样,貌似应该是有种贪心策略,把最大的挑出来最后还有5块钱的再买,剩下的体积用01背包去求最优选择,当时WA了3次,以为 ...

最新文章

  1. DiscuzNT 商品交易插件设计之[线下交易流程]
  2. LVS的DR工作模型解析
  3. 两个byte[]拼接
  4. 基于Boost::beast模块的快速WebSocket服务器
  5. iOS之深入解析保证线程安全的“锁”的使用和性能分析
  6. 程序详细设计之代码编写规范_我在不编写任何代码的情况下建立了一个设计策划网站
  7. oracle sql plus 常用命令
  8. LINUX 第六章 Open WebMail完全安装手册
  9. 【Jenkins】Jenkins : jenkins-2.121.1 安装 与 使用
  10. 彻底理解position与anchorPoint - Wonderffee's Blog(转)
  11. Linux下patch打补丁命令
  12. 如何免费下载网易云收费音乐?不需会员也能做到
  13. intellij idea 15 万恶的光标跟随
  14. matlab sg3525仿真,基于SG3525的直流升压电源的设计与仿真
  15. IDEA 不检查语法错误问题
  16. Infor SunSystems咨询服务市场报告-市场规模、市场份额、市场定位、产品类型以及发展规划
  17. 浅谈公安部声纹数据库的建设与应用
  18. python如何实现图像中特定颜色的种类识别及特定颜色的占比代码
  19. 《内网安全攻防:渗透测试实战指南》读书笔记(八):权限维持分析及防御
  20. iOS 最新版9.3 disk image

热门文章

  1. 组件通信 Provideinject
  2. Vue -- element-ui el-table 的合计在第一行显示并可点击
  3. IOS —— KVO的一个小封装
  4. DecimalFormat格式化输出带小数的数字类型
  5. 【Redis】2、CentOS 7 上安装 redis3.2.3安装与配置
  6. rabbitmq最大连接数(Socket Descriptors)
  7. make file教程(转)
  8. C# 关闭正在执行的文件
  9. asp.net mvc中ckeditor+ckfinder的配置方法
  10. 测试集的构成比例对网络分类性能的影响cp