codeforces_302D
2 seconds
256 megabytes
standard input
standard output
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
1000 一开始当作搜索来做,发现有问题,读题要全面分析,最后看题解,发现是一个最短路问题。
思路:知道是最短路后,就是一个简单题,用floyd过掉。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define INF 99999999
int n,d;
int map[][]; void init()
{
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
{
if(i==j)
map[i][j]=;
else
map[i][j]=INF;
}
} int add[];
int loca[][];
int main()
{
scanf("%d%d",&n,&d);
init();
for(int i=; i<n; i++)
scanf("%d",&add[i]);
for(int i=; i<=n; i++)
scanf("%d%d",&loca[i][],&loca[i][]);
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
if(i!=j)
map[i][j]=(abs(loca[i][]-loca[j][])+abs(loca[i][]-loca[j][]))*d-add[j];
for(int k=; k<=n; k++)
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
map[i][j]=min(map[i][j],map[i][k]+map[k][j]);
printf("%d\n",map[][n]);
return ;
}
codeforces_302D的更多相关文章
随机推荐
- 浅谈MySQL Capabilities --从调研PHP mysqlnd源码细节角度认识
今天一起来研究下MySQL Capabilities,这个非常重要,如果大家有想法自己动手实现一个MySQL客户端或者Proxy工具,那么就得先了解一下这块,正好PHP 5.3以上版本由于官方为了规避 ...
- 为何被主流抛弃-江西IDC机房价格为何居高不下缺少竞争力-2014年5月江西IDC排行榜
经常有人问江西IDC排行榜,为什么江西市场缺乏活力. 榜单调研者们有时仅仅能表示无解和无奈. 在IDC领域,其实已经形成了一二三线的城市之分. 一线城市是以上海.北京.深圳为代表的拥有最早国际宽 ...
- js全局替换空格,制表符,换行符
this.value = this.value.replace(/\s+/g,'') "/ "这个是固定写法, "\s"匹配任何不可见字符,包括空格.制表符.换 ...
- 万一的Delphi消息教程
http://www.cnblogs.com/del/category/134064.html
- 容器ArrayList原理(学习)
一.概述 动态数组,容量能动态增长,元素可以为null,用数组存储,非线程同步(vector线程同步) 每个 ArrayList 实例都有一个容量,该容量是指用来存储列表元素的数组的大小,自动增长(默 ...
- HDU 5763Another Meaning
Another Meaning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 单独编译framework【转】
本文转载自:http://blog.csdn.net/u011168565/article/details/53782325 参考文章: http://bbs.csdn.net/topics/3701 ...
- git服务器的建立
git简介 首先,与以前广为流行的SVN不同,git是分布式的,其没有服务器端与客户端之分(虽然在项目管理过程中,一般会人为地指定某一台非开发用的机器作为“服务器”,但就git自身功能来说,完全可以没 ...
- 从csv文件读取数据到二维vector
void ReadDataFromCsv(std::string &filename, std::vector<std::vector<std::string> > & ...
- bzoj4818
http://www.lydsy.com/JudgeOnline/problem.php?id=4818 矩阵快速幂+dp 首先我们来写一个dp dp[i][j]:选到第i个数,和为j,复杂度nm,不 ...