栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3031 Robotruck

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3031 Robotruck

#include <iostream>#include <stdio.h>#include <string.h>#include <math.h>using namespace std;#define LL long longconst int maxn=100005;struct node{ int x,y; int w;};node p[maxn];int q[maxn];LL d[maxn],w[maxn],f[maxn];int c,n,t;int abs(int x){ return x<0?(-x):x;}LL dis(int a,int b){ return abs(p[a].x-p[b].x)+abs(p[a].y-p[b].y);}void dp(){ int head=0,tail=0,i; q[tail++]=0; f[0]=0; for (i=1;i<=n;i++) { while (head<tail && w[i]-w[q[head]]>c) head++; int j=q[head]; f[i]=f[j]+dis(0,j+1)+d[i]-d[j+1]+dis(i,0); while (head<tail) { int j=q[tail-1]; if (f[j]+dis(0,j+1)-d[j+1] < f[i]+dis(0,i+1)-d[i+1]) break; tail--; } q[tail++]=i; } printf("%lldn",f[n]);}int main(){ int i; scanf("%d",&t); while (t--) { scanf("%d",&c); scanf("%d",&n); for (i=1;i<=n;i++) scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].w); p[0].x=0; p[0].y=0; d[0]=0; w[0]=0; for (i=1;i<=n;i++) { d[i]=d[i-1]+dis(i-1,i); w[i]=w[i-1]+(LL)p[i].w; } dp(); } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/380039.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号