uva1336 Fixing the Great Wall
用到了kase避免memset超时
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cassert>
using namespace std; const int maxn = + ;
const double INF = 1e30; struct Section {
double x, c, dt;
bool operator < (const Section& rhs) const {
return x < rhs.x;
}
} s[maxn]; int kase, n;
int vis[maxn][maxn][];
double v, x, d[maxn][maxn][];
double psdt[maxn]; // prefix sum of dt // cost accumulated when walking from x1 and x2.
// section[i~j] are already finished
double cost(double x1, double x2, int i, int j) {
double finished_dt = ;
assert(i <= j);//not necessary
if(i >= && j >= ) finished_dt += psdt[j] - psdt[i-]; // -1 -1�����
return (psdt[n] - finished_dt) * fabs(x2 - x1) / v;
} double dp(int i, int j, int p) { //p=0��ǰ��i,p=1��ǰ��j
if(i == && j == n) return ;
double& ans = d[i][j][p];
if(vis[i][j][p] == kase) return ans;
vis[i][j][p] = kase; ans=INF;
double x = (p == ? s[i].x : s[j].x);
if(i > ) ans = min(ans, dp(i-, j, ) + cost(x, s[i-].x, i, j));
if(j < n) ans = min(ans, dp(i, j+, ) + cost(x, s[j+].x, i, j));
return ans;
} int main() {
memset(vis, , sizeof(vis));
while(scanf("%d%lf%lf", &n, &v, &x) == && n) {
kase++;
double sumc = ;
for(int i = ; i <= n; i++) {
scanf("%lf%lf%lf", &s[i].x, &s[i].c, &s[i].dt);
sumc += s[i].c;
}
sort(s+, s+n+); psdt[] = ;
for(int i = ; i <= n; i++)
psdt[i] = psdt[i-] + s[i].dt; s[].x = -INF;
s[n+].x = INF;
double ans = INF;
for(int i = ; i <= n+; i++)
if(x > s[i-].x && x < s[i].x) {
if(i > )
ans = min(ans, dp(i-, i-, ) + cost(x, s[i-].x, -, -)); // move left
if(i <= n)
ans = min(ans, dp(i, i, ) + cost(x, s[i].x, -, -)); // move right
break;
}
printf("%.0lf\n", floor(ans + sumc));
}
return ;
}
uva1336 Fixing the Great Wall的更多相关文章
- UVA-1336 Fixing the Great Wall(区间DP)
题目大意:长城(视作x正半轴)有n处破损.有一个智能修复机器人,它的初始位置和移动速度已知.每处破损处都有一组参数(x,c,d),x表示位置,c.d表示在时间t后再修复该处破损的花费为d*t+c.求用 ...
- 【杂题总汇】UVa-1336 Fixing the Great Wall
[UVA-1336]Fixing the Great Wall 一开始把题看错了……直接用的整数存储答案:之后用double存最后输出答案的时候取整就AC了
- 【暑假】[深入动态规划]UVa 10618 Fixing the Great Wall
UVa 10618 Fixing the Great Wall 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=361 ...
- Fixing the Great Wall
题意: 在一条线上,有n个坏的地方要修机器人修,机器人的移动速度V,若坏的地方立即被修花费ci,若没修,每单位时间增加d,出去机器人的开始位置,求修完n个地方的最小花费. 分析: 非常经典,求解“未来 ...
- UVa 1336 Fixing the Great Wall (区间DP)
题意:给定 n 个结点,表示要修复的点,然后机器人每秒以 v 的速度移动,初始位置在 x,然后修复结点时不花费时间,但是如果有的结点暂时没修复, 那么每秒它的费用都会增加 d,修复要花费 c,坐标是 ...
- 【Uva 1336】Fixing the Great Wall
[Link]: [Description] 给你长城上的n个修补点,然后你的位置为x; 你需要依次去这n个点,然后把它们全部修好. 但是修的前后顺序不一样的话,花费不一样. 如果立即把第i个点修好的话 ...
- 2021record
2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...
- [SinGuLaRiTy] 动态规划题目复习
[SinGuLaRiTy-1026] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [UVA 1025] A Spy in the Metr ...
- [poj1113][Wall] (水平序+graham算法 求凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
随机推荐
- Python项目使用memcached缓存
前言许多Web应用都将数据保存到MySQL这样的关系型数据库管理系统中,应用服务器从中读取数据并在浏览器中显示. 但随着数据量的增大.访问的集中,就会出现数据库的负担加重.数据库响应恶化. 网站显示延 ...
- VC将同一份代码同时编译为Dll和Exe的方法
开发中经常遇到这样的情况,需要开发一个某某功能的接口Dll,但是Dll不能直接调试,你至少需要一个Loader 但是Loader和Dll本身不在同一个工程里,虽然都在本机的话并不影响源码级调试,但是总 ...
- HTTP错误code大全
100 - Continue 101 - Switching Protocols Top Success Codes 200 - OK 201 - Created 202 - Accepted 203 ...
- 安装JDK+Eclipse+Maven+Git/Gitee(windows系统和linux系统)
1. 安装JDK 官网下载 下载java SE 下载 Java SE 7 1.1 windows配置jdk windows配置jdk 1.2 Ubuntu配置jdk Ubuntu 安装 JDK 7 / ...
- Collection View Programming Guide for iOS---(六)---Creating Custom Layouts
Creating Custom Layouts 创建自定义布局 Before you start building custom layouts, consider whether doing so ...
- c++ 头文件 及 sort 和 vector简单介绍
c++ sort :http://www.16kan.com/post/997260.html http://wenku.baidu.com/view/e064166daf1ffc4ffe47ac6 ...
- Javascript中的回调函数和匿名函数的回调示例介绍
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- poj 3734 Blocks【指数型生成函数】
指数型生成函数,推一推可得: \[ (1+\frac{x^1}{1!}+\frac{x^2}{2!}+\frac{x^3}{3!}+...)^2+(1+\frac{x^2}{2!}+\frac{x^4 ...
- bzoj 4753: [Jsoi2016]最佳团体【01分数规划+二分+树上背包】
01分数规划,二分答案然后把判别式变成Σp[i]-Σs[i]*mid>=0,然后树上背包判断,设f[i][j]为在i点子树里选j个的最大收益,随便背包一下就好 最丧病的是神卡常--转移的时候要另 ...
- Apereo CAS Server服务端搭建教程
不说废话了,直接看搭建过程吧. 首先到下载源码,https://github.com/apereo/cas-overlay-template/tree/4.2 附上地址,本次版本为4.2,下载源码后如 ...