hdu 5037 周期优化
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 周期优化的更多相关文章
- 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( ...
- hdu 5037 Frog(贪心)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5037 题解:为了让放的石头有意义肯定是没l+1的距离放2个也就是说假设现在位置为pos那么 ...
- hdu 3507 斜率优化
我的第一道斜率优化. 就这道题而言,写出原始的方程: dp[i] = min{ dp[j] + (sum[i]-sum[j])2 + M | j in [0,i) } O(n^2)的复杂度肯定超时, ...
- HDU 4258 斜率优化dp
Covered Walkway Time Limit: 30000/10000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- HDU 2844 二进制优化的多重背包
Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- hdu 2490 队列优化dp
http://acm.hdu.edu.cn/showproblem.php?pid=2490 Parade Time Limit: 4000/2000 MS (Java/Others) Memo ...
- HDU 2829 斜率优化DP Lawrence
题意:n个数之间放m个障碍,分隔成m+1段.对于每段两两数相乘再求和,然后把这m+1个值加起来,让这个值最小. 设: d(i, j)表示前i个数之间放j个炸弹能得到的最小值 sum(i)为前缀和,co ...
- hdu 5037 Frog 贪心 dp
哎,注意细节啊,,,,,,,思维的严密性..... 11699193 2014-09-22 08:46:42 Accepted 5037 796MS 1864K 2204 B G++ czy Frog ...
- hdu 3669(斜率优化DP)
Cross the Wall Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 327680/327680 K (Java/Others) ...
随机推荐
- scala 建模
// train multinomial logistic regression val lr = new LogisticRegressionWithLBFGS() .setIntercept(tr ...
- break、continue、pass介绍
break.continue.pass介绍 break:跳出当前循环 continue:跳出本次循环,进行下一次循环 pass:什么也不做,占位.
- sysdig
centos 7 安装 https://sysdig.com/opensource/sysdig/install/ 1) Trust the Draios GPG key, configure the ...
- mysql 用户及赋予权限
查询用户: use mysql; select host,user from mysql.user; 创建用户: create user 'mhc'@'%' identified by 'mhc.12 ...
- vs2010+Aspx进行sharepoint2010工作流开发(3) 资料整理
http://www.cnblogs.com/janet/archive/2010/04/24/1719315.html http://www.cnblogs.com/poissonnotes/arc ...
- for循环计算阶乘的和,for循环计算阶乘倒数的和
计算阶乘的和 //阶乘的和,5!+4!+3!+2! int a = 5; for(int b = 4; b > 0; b--) { a = a * b; } //先定义好最大数的阶乘是多少 in ...
- 前端知识--------HTML内容
HTML介绍 1.web服务本质 import socket sk = socket.socket() sk.bind(('127.o.o.1',8080)) sk.listen() while 1: ...
- Array Product(模拟)
Array Product http://codeforces.com/problemset/problem/1042/C You are given an array aa consisting o ...
- httplib:AttributeError: 'module' object has no attribute 'HTTPConnection'
# -*-coding:gb2312-*- #Function:学习python的httplib模块 import httplib conn = httplib.HTTPConnection(&quo ...
- mybatis sql语句符号问题
写sql语句<或>不能直接写,而应写作<或>,不然项目不能正常编译启动