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的更多相关文章
随机推荐
- Hibernate学习笔记(六) — Hibernate的二级缓存
我们知道hibernate的一级缓存是将数据缓存到了session中从而降低与数据库的交互.那么二级缓存呢? 一.应用场合 比方.在12306购票时.须要选择出发地与目的地,假设每点一次都与数据库交互 ...
- Linux下的文件夹创建命令使用实践
[文章摘要] 本文以实际的C源程序为样例,介绍了Linux下的文件夹创建命令(mkdir)的用法.为相关开发工作的开展提供了故意的參考. [关键词] C语言 Linux 文件夹创建 makefi ...
- Wordpress 建站(一)
去年在美国的justhost上买了两个域名(shanyexuanyu.com 和 chenjinyu.net.shanyexuanyu.com是给一位马来西亚的佛教徒朋友做的站点. 她镜头下佛教的文 ...
- 12.解决CCScale9Sprite或者CCControlButton无法使用的问题。
问题: 使用CCScale9Sprite或者CCControlButton等控件的时候,会出现无法识别的情况. 解决方式: 1.include对应的头部,即#include "cocos-e ...
- iOS MMDrawerController源码解读(一)
提前说好,本文绝对不是教你如何使用MMDrawerController这个第三方库,因为那太多人写了 ,也太简单了.这篇文章主要带你分析MMDrawerController是怎么实现抽屉效果,明白 ...
- unity3D游戏开发实战原创视频讲座系列13之帽子戏法游戏开发(预告)
文件夹 第一讲 游戏演示项目创建 第二讲 游戏场景的编辑 第三讲 帽子的移动 第四讲 炮弹的产生 第六讲 游戏界面的完好 第七讲 各种UI的制作 第八讲 分数和爆炸特效 视持续更新中.. ...
- java json字符串转成 Map或List
import java.util.List; import java.util.Map; import java.util.Map.Entry; import net.sf.json.JSONArra ...
- 关于spring配置文件中编辑时没有提示信息的问题
spring配置文件头部信息主要是提供一个xml的编写规范作用. 新创建的配置文件引入头部信息后,编辑时没有提示信息,重启elipse即可解决.
- Hierarchyviewer定位Android图片资源的研究
之前就在研究能否通过Hierarchyviewer找到所有所见的资源 在导入Hierarchyviewer之后才发现绑定在View上的drawable与实际的图片资源之间并没有维系着一个固定的对应关系 ...
- 【Silverlight】Bing Maps学习系列(五):绘制多边形(Polygon)图形(转)
[Silverlight]Bing Maps学习系列(五):绘制多边形(Polygon)图形 Bing Maps Silverlight Control支持用户自定义绘制多边形(Polygon)图形, ...