http://acm.hdu.edu.cn/showproblem.php?pid=5037

有只青蛙踩石子过河,河宽m,有n个石子坐标已知。青蛙每次最多跳L。现在可以在河中再放一些石子,使得青蛙过河跳的次数最多。

青蛙是贪心的,如果它现在在cur位置跳不动了,且它上一次所在位置为pre。那么God肯定要把新石子放在max(cur,pre+L)+1的位置。

使用模拟+周期优化

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
const int maxn = 200005;
int n,m,l,s[maxn];
int main (){
int _,cas = 1;
RD(_);
while(_--){
printf("Case #%d: ",cas++);
RD(n);RD2(m,l);
for(int i = 0;i < n;++i)
RD(s[i]);
sort(s,s+n);
s[n++] = m;
int ans = 0,pre = -l,cur = 0;
for(int i = 0;i < n;++i){//cout<<i<<endl;
int t = (s[i] - cur)/(l+1);
pre += t*(l+1);
ans += t*2;
if(s[i] - pre <= l){
cur = s[i];
}else if(s[i] - pre > l){
ans++;
pre = cur + t*(l+1);
cur = s[i];
}
}
printf("%d\n",ans);
}
return 0;
}

hdu 5037 周期优化的更多相关文章

  1. HDU 2608 底数优化分块 暴力

    T(n) as the sum of all numbers which are positive integers can divied n. and S(n) = T(1) + T(2) + T( ...

  2. hdu 5037 Frog(贪心)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5037 题解:为了让放的石头有意义肯定是没l+1的距离放2个也就是说假设现在位置为pos那么 ...

  3. hdu 3507 斜率优化

    我的第一道斜率优化. 就这道题而言,写出原始的方程: dp[i] = min{ dp[j] + (sum[i]-sum[j])2  + M | j in [0,i) } O(n^2)的复杂度肯定超时, ...

  4. HDU 4258 斜率优化dp

    Covered Walkway Time Limit: 30000/10000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  5. HDU 2844 二进制优化的多重背包

    Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. hdu 2490 队列优化dp

    http://acm.hdu.edu.cn/showproblem.php?pid=2490 Parade Time Limit: 4000/2000 MS (Java/Others)    Memo ...

  7. HDU 2829 斜率优化DP Lawrence

    题意:n个数之间放m个障碍,分隔成m+1段.对于每段两两数相乘再求和,然后把这m+1个值加起来,让这个值最小. 设: d(i, j)表示前i个数之间放j个炸弹能得到的最小值 sum(i)为前缀和,co ...

  8. hdu 5037 Frog 贪心 dp

    哎,注意细节啊,,,,,,,思维的严密性..... 11699193 2014-09-22 08:46:42 Accepted 5037 796MS 1864K 2204 B G++ czy Frog ...

  9. hdu 3669(斜率优化DP)

    Cross the Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others) ...

随机推荐

  1. Interface, 接口的实现初解

    百度是这么说的: Java接口是一系列方法的声明,是一些方法特征的集合,一个接口只有方法的特征没有方法的实现,因此这些方法可以在不同的地方被不同的类实现,而这些实现可以具有不同的行为(功能). 两种含 ...

  2. The Last Stand

    The Last Stand https://ac.nowcoder.com/acm/contest/303/L 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语 ...

  3. 安装配置Windows Live Writer做为博客客户端

    前言: 国内好些空间.博客是支持Windows Live Writer客户端的,也就是说使用Windows Live Writer不用登陆博客网站,就可以向不同的博客网站发布博客了. Windows ...

  4. UVa 10763 Foreign Exchange(map)

    Your non-profitorganization (iCORE - international Confederationof Revolver Enthusiasts) coordinates ...

  5. java web 常用正则

    什么是 RegExp? RegExp 是正则表达式(Regular expression)的缩写,作用是对字符串执行模式匹配. 通常用于格式验证.正则替换.查找子串等 各种编程语言的正则表达式基本相同 ...

  6. GridView上同时定义了 DataSource 和 DataSourceId

    VS平台下ASP.NET网站的建立,我们常常要跟数据库打交道,获取数据库的信息,通过GridView控件进行显示,需要为GridView指定 DataSourceId或者DataSource,切忌不可 ...

  7. win 下 nginx 与 php的配置

    1.下载需要的软件包 php的windows版本(*注意这里下载非线程安全的,nginx使用的是cgi) http://windows.php.net/download/   nginx的window ...

  8. php的反射

    我们可以在PHP运行时,通过PHP的反射动态的获取类的方法.属性.参数等详细信息.   用途:插件的设计,文档的自动生成,扩充PHP语言. <?php class Person { const ...

  9. Spring框架中的工厂(了解)

    1. ApplicationContext接口 * 使用ApplicationContext工厂的接口,使用该接口可以获取到具体的Bean对象 * 该接口下有两个具体的实现类 * ClassPathX ...

  10. C#6.0新特性:var s = $"{12}+{23}={12+23}"

    为什么会出现$符号,c#6.0才出现的新特性 var s = string.Fromat("{0}+{1}={2}",12,23,12+23) 用起来必须输入string.From ...