用到了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的更多相关文章

  1. UVA-1336 Fixing the Great Wall(区间DP)

    题目大意:长城(视作x正半轴)有n处破损.有一个智能修复机器人,它的初始位置和移动速度已知.每处破损处都有一组参数(x,c,d),x表示位置,c.d表示在时间t后再修复该处破损的花费为d*t+c.求用 ...

  2. 【杂题总汇】UVa-1336 Fixing the Great Wall

    [UVA-1336]Fixing the Great Wall 一开始把题看错了……直接用的整数存储答案:之后用double存最后输出答案的时候取整就AC了

  3. 【暑假】[深入动态规划]UVa 10618 Fixing the Great Wall

    UVa 10618 Fixing the Great Wall 题目:  http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=361 ...

  4. Fixing the Great Wall

    题意: 在一条线上,有n个坏的地方要修机器人修,机器人的移动速度V,若坏的地方立即被修花费ci,若没修,每单位时间增加d,出去机器人的开始位置,求修完n个地方的最小花费. 分析: 非常经典,求解“未来 ...

  5. UVa 1336 Fixing the Great Wall (区间DP)

    题意:给定 n 个结点,表示要修复的点,然后机器人每秒以 v 的速度移动,初始位置在 x,然后修复结点时不花费时间,但是如果有的结点暂时没修复, 那么每秒它的费用都会增加 d,修复要花费 c,坐标是 ...

  6. 【Uva 1336】Fixing the Great Wall

    [Link]: [Description] 给你长城上的n个修补点,然后你的位置为x; 你需要依次去这n个点,然后把它们全部修好. 但是修的前后顺序不一样的话,花费不一样. 如果立即把第i个点修好的话 ...

  7. 2021record

    2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...

  8. [SinGuLaRiTy] 动态规划题目复习

    [SinGuLaRiTy-1026] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. [UVA 1025] A Spy in the Metr ...

  9. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

随机推荐

  1. 【POJ 1061】 青蛙的约会

    [题目链接] 点击打开链接 [算法] 列出同余方程,然后用exgcd求解 [代码] #include <algorithm> #include <bitset> #includ ...

  2. sourceTree 的使用

    一.拉取其他分支代码 1.git clone 代码是下载master分支 2.在未做修改的情况下,合并分支 二.提交代码到其他分支 1.创建分支(名称可以与远程不同) 2.(正常提交步骤)将作出的修改 ...

  3. 土法搞docker系列之自制docker的graph driver vdisk

    写在最前 偶然整理,翻出来14年刚开始学docker的时候的好多资料.当时docker刚刚进入国内,还有很多的问题.当时我们的思考方式很简单,docker确实是个好的工具,虽然还不成熟.但是不能因为短 ...

  4. Node学习图文教程之express重写留言本案例

    写在前面 小伙伴们大家好,我是你们的pubdreamcc,接着前面的学习,这篇博文出至于我的GitHub仓库:Node学习教程资料,如果你觉得对你有帮助,欢迎star,你们的点赞是我持续更新的动力,谢 ...

  5. tpframe免费开源框架又一重大更新

    tpframe在为Pc站.app接口.微信mobile站各种功能完善的基础上,又更新了一项重新的更新突破,以后你用tpframe开发网站,不须要在写那么多繁琐的依赖程序了,现在只须要写你关注的程序模块 ...

  6. Hello world——程序员的第一篇代码

    Hello world 是和A+B问题并驾齐驱的一道题,也是当世的经典题之一. 题目: 输出“Hello world”    样例输入 样例输出    Hello world Hello world ...

  7. 关于Page翻页效果, PageViewConrtoller

    Page View Controllers你使用一个page view controller用page by page的方式来展示内容.一个page view controller管理一个self-c ...

  8. poj 1723 Soldiers【中位数】By cellur925

    题目传送门 题目大意:平面上有n个士兵,给出每个士兵的坐标,求出使这些士兵站好所需要的最少移动步数.站好要求:所有士兵y相等,x相邻.即达到 (x,y), (x+1, y), (x+2,y)……的状态 ...

  9. hdu 5409 CRB and Graph(边双联通分量)

    题意: 给一个图一些边,保证图连通 问对于每条边,如果去除该边后使得图中一些点不连通.设这些点(u,v),要求使u尽量小,v尽量大,输出这样的(u,v).否则输出0 0. #include <b ...

  10. LIS && LCS && LCIS && LPS && MCS模板

    1. LIS (Longest Increasing Subsequence) O (n^2): /* LIS(Longest Increasing Subsequence) 最长上升子序列 O (n ...