Yaroslav is playing a game called "Time". The game has a timer showing the lifespan he's got left. As soon as the timer shows 0, Yaroslav's character dies and the game ends. Also, the game has n clock stations, station number i is at point (xi, yi) of the plane. As the player visits station number i, he increases the current time on his timer by ai. The stations are for one-time use only, so if the player visits some station another time, the time on his timer won't grow.
A player spends d·dist time units to move between stations, where dist is the distance the player has covered and d is some constant. The distance between stations i and j is determined as |xi - xj| + |yi - yj|.
Initially, the player is at station number 1, and the player has strictly more than zero and strictly less than one units of time. At station number 1 one unit of money can increase the time on the timer by one time unit (you can buy only integer number of time units).
Now Yaroslav is wondering, how much money he needs to get to station n. Help Yaroslav. Consider the time to buy and to increase the timer value negligibly small.
The first line contains integers n and d (3 ≤ n ≤ 100, 103 ≤ d ≤ 105) — the number of stations and the constant from the statement.
The second line contains n - 2 integers: a2, a3, ..., an - 1 (1 ≤ ai ≤ 103). The next n lines contain the coordinates of the stations. The i-th of them contains two integers xi, yi (-100 ≤ xi, yi ≤ 100).
It is guaranteed that no two stations are located at the same point.
In a single line print an integer — the answer to the problem.
3 1000 1000 0 0 0 1 0 3
2000
3 1000 1000 1 0 1 1 1 2
1000Floyd 滚啊滚~~滚滚就出来了 滚之前要把距离先减掉a[x]。#include <cstdio> #include <iostream> #include <cmath> #include <string> #include <cstring> #include <cstdlib> #include <algorithm> #include <stack> #include <map> #include <set> #include <vector> #include <queue> #define ll long long using namespace std; const int INF = 0x3f3f3f3f; int d,n; int a[105]; int x[105],y[105]; int g[105][105]; bool vis[105]; int dis[105]; int Distance(int i,int j) { return abs(x[j]-x[i])+abs(y[j]-y[i]); } void floyd() { for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(g[i][j]>g[i][k]+g[k][j]&& i!=j && j!=k && i!=k) g[i][j]=g[i][k]+g[k][j]; cout<<g[1][n]<<endl; } int main() { //freopen("input.txt","r",stdin); cin>>n>>d; int ttt; for(int i=2;i<n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) cin>>x[i]>>y[i]; a[1]=a[n]=0; for(int i=1;i<=n;i++){ g[i][i]=0; for(int j=i+1;j<=n;j++){ g[i][j]=Distance(i,j)*d-a[j]; g[j][i]=Distance(j,i)*d-a[i]; } } floyd(); return 0; }
还有 当时耍小聪明吧每个数直接/d了,wa了n多次之后才发现这么写好像不对额 可能是a[x]与d不成倍数关系吧=o=