用到了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. 笔记本创建wifi热点

    如何在Win8系统上建立WIFI热点 | 浏览: 2511 | 更新: 2013-04-10 01:55 | 标签: win8 59 28 全文阅读分步阅读   步骤 1 2 3 4 5 6 7 8 ...

  2. atof和atoi

    atof:将字串转换成浮点型数 表头文件 #include <stdlib.h> 函数说明 atof()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而 ...

  3. Codeforces - 1117E - Crisp String - 进制 - 交互

    https://codeforces.com/problemset/problem/1117/E 就用abc表示数字来给每个数编码,编完直接问出移动的结果,反构造就行了,比C和D还简单. #inclu ...

  4. EOJ3247:铁路修复计划

    传送门 题意 分析 这题用二分做就好啦,有点卡常数,改了几下for的次数 套了个板子,连最小生成树都忘记了QAQ trick 代码 #include<cstdio> #include< ...

  5. 2016 Multi-University Training Contest 3 1011【鸽巢原理】

    题解: 坐标(0,m)的话,闭区间,可能一共有多少曼哈顿距离? 2m 但是给一个n,可能存在n(n+1)/2个曼哈顿距离 所以可以用抽屉原理了 当n比抽屉的数量大,直接输出yes 不用计算 那...N ...

  6. P5161 WD与数列(后缀自动机+线段树合并)

    传送门 没想出来→_→ 首先不难看出要差分之后计算不相交也不相邻的相等子串对数,于是差分之后建SAM,在parent树上用线段树合并维护endpos集合,然后用启发式合并维护一个节点对另一个节点的贡献 ...

  7. JAVA多线程(四) Executor并发框架向RabbitMQ推送消息

    github代码地址: https://github.com/showkawa/springBoot_2017/tree/master/spb-demo/spb-brian-query-service ...

  8. 前端笔记之React(二)组件内部State&React实战&表单元素的受控

    一.组件内部的State 1.1 state state叫状态,是每一个类式组件都有的属性,但函数式组件,没有state. state是一个对象,什么值都可以定义. 在任何类式组件的构造函数中,可以用 ...

  9. 黑客攻防技术宝典web实战篇:攻击用户·其他技巧习题

    猫宁!!! 参考链接:http://www.ituring.com.cn/book/885 随书答案. 1. 已知一项应用程序功能将一个查询字符串参数的内容插入到某个 HTTP 重定向的 Locati ...

  10. jQuery中$.getJSON

    $.getJSON $.getJSON()是专门为ajax获取json数据而设置的,并且支持跨域调用,其语法的格式为: $.getJSON( url, //请求URL [data], //传参,可选参 ...