地图上有n个点(x,y),机器人从(0,0) 出发到每个点捡垃圾(w[i]) ,承载最大重量为m
在每个点都可以返回(0,0)点放置垃圾
最短路程? n<1e5,m<100
看完范围只能设 f[i] ,考虑前i个点,返回原地所走的最短路程,
d[i] = min{ d[j] + dis0(j+1) + dis0(i) + dist(i,j+1) } j<=i, w(j+1,i)<=C
前缀和搞一下 dist(i,j+1) = s[i] - s[j+1]
带入化简
d[i] =min{ func(j) | w(j+1,i) <=C } +s[i] +dis0(i) func(j)=d[j]-s[j+1]+dis0(j+1)
是个滑动窗口模型
#include <iostream> #include <algorithm> #include <queue> #include <cmath> using namespace std; const int N=1e5+2; int C,n,s[N],f[N],dis[N],x[N],y[N],sw[N]; int F(int i){ return f[i]-s[i+1]+dis[i+1]; } void solve(){ cin>>C>>n; int i,z; for(i=1;i<=n;i++){ cin>>x[i]>>y[i]>>z; dis[i]=abs(x[i])+abs(y[i]); s[i]=s[i-1]+abs(x[i]-x[i-1])+abs(y[i]-y[i-1]); sw[i]=sw[i-1]+z; } deque<int> q; q.push_back(0); for(i=1;i<=n;i++){ while(!q.empty()&&sw[i]-sw[q.front()]>C) q.pop_front(); f[i]=F(q.front())+s[i]+dis[i]; while(!q.empty()&&F(i)<=F(q.back())) q.pop_back(); q.push_back(i); } cout<<f[n]<<endl; } signed main(){ //freopen("out","w",stdout); int cas; cin>>cas; while(cas--) solve(); }
标签:int,sw,1169,abs,uva,include,dis From: https://www.cnblogs.com/towboa/p/16834247.html