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的更多相关文章
随机推荐
- (源代码分析)Android-Universal-Image-Loader (图片异步载入缓存库)的使用配置
转载请注明出处:http://blog.csdn.net/u011733020 前言: 在Android开发中,对于图片的载入能够说是个老生常谈的问题了,图片载入是一个比較坑的地方.处理不好,会有各种 ...
- StringBuffer疑问
为何结果为AB.B? public static void main(String[] args) { StringBuffer a=new StringBuffer("A"); ...
- HDU Today HDU杭电2112【Dijkstra || SPFA】
http://acm.hdu.edu.cn/showproblem.php?pid=2112 Problem Description 经过锦囊相助,海东集团最终度过了危机,从此.HDU的发展就一直顺风 ...
- MySQL-插入数据(INSERT)
Insert语句可将一行或多行插入到表中. INSERT语法: INSERT INTO table(column1,column2...) VALUES (value1,value2,...); 首先 ...
- 单点登录之CAS简介
cas官网http://www.ja-sig.org/products/cas/. ok,如今開始本文的重点内容解说,先来了解一下cas 实现single sign out的原理,如图所看到的: ...
- 解决ubuntu中firefox浏览器总是提示找不到server的问题
这个情况在我机器上常常出现,并且时不时的给你出点问题.可是有些时候等一下就好了.或者把引擎换到百度的话它就又行得通了.. 被这个问题搞得非常烦.上网查了下说是防火墙啊之类的出问题.可是自己弄了后这个问 ...
- 《ASP.NET4 从入门到精通》学习笔记4
第4部分诊断与插件 刚開始看这章的时候,真实一头雾水.不知道在讲什么.只是看了关于http pipeline之后.才了解相关说明. 因此对于这一章的学习,建议各位首先看看http pipeline然后 ...
- c# 获取根节点的属性信息
<?xml version="1.0" encoding="UTF-8"?> <!--课程封面信息 --> <GK version ...
- NTFS文件系统的单个文件最大到底有多大?
于NTFS文件系统的单个文件最大到底有多大? 闲来无事突然想到这个问题,到网上搜索了一下也没有一个固定的解释. 于是到微软官方知识库去寻找答案: 注意:基础硬件限制可能会对任何文件系统施加额外的分区大 ...
- Vijos 1565 多边形 【区间DP】
描述 zgx给了你一个n边的多边形,这个多边形每个顶点赋予一个值,每条边都被标上运算符号+或*,对于这个多边形有一个游戏,游戏的步骤如下:(1)第一步,删掉一条边:(2)接下来n-1步,每步对剩下的边 ...