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的更多相关文章
随机推荐
- Lvs 负载均衡 (VS/NAT模式)
一.LVS简介 LVS是 Linux Virtual Server 的简称,也就是Linux虚拟服务器.这是一个由章文嵩博士发起的一个开源项目,它的官方网站是 http://www.linuxvirt ...
- Linux 内核开发 - 内存管理
1.1什么是内存管理 内存管理是对计算机内存进行分配和使用的技术.内存管理主要存在于多任务的操作系统中,因为内存资源极其有限.须要在不同的任务之间共享内存,内存管理的存在就是要高效.高速的非配内存,并 ...
- 南阳oj 语言入门 A+B paoblem 题目477 题目844
A+Bproblem 题目844 两个数字翻转后相加 比方10+12 翻转后01+21=22 #include<stdio.h> int main() { int ji(in ...
- height not divisible by 2
height not divisible by 2 h.264 - FFMPEG (libx264) "height not divisible by 2" - Stack Ove ...
- go10---struct
package main import ( "fmt" ) type test struct{} //空的结构体 type person struct { name string ...
- 在linux上处理base64加密和解密
http://snailwarrior.blog.51cto.com/680306/142472/ 2.从标准输入读取文件内容,base64编码并打印到标准输出 [root@localhost tes ...
- 控件CListCtr详解
1.CListCtrl控件 CListCtrl控件在数据库编程中是用得比较多的控件之一,也是Window控件中较难掌握的一个控件.他可以有四显示方式,Report.List.Icon.SmallIco ...
- 英式英语 vs 美式英语
0. 常见不同 日期的表达: 美国:月日年: 英国:日月年: 1. 发音 schedule,美 ['skɛdʒul],英 [ˈʃɛdjuːl] pecan,山核桃,英 ['piːk(ə)n;],美 [ ...
- POJ2069 最小球覆盖 几何法和退火法
对这种问题不熟悉的读者 可以先去看一看最小圆覆盖的问题 ZOJ1450 现在我们来看最小球覆盖问题POJ2069 题目很裸,给30个点 求能覆盖所有点的最小球的半径. 先给出以下几个事实: 1.对于一 ...
- Objective-C 继承与类
创建: 2018/01/20 完成: 2018/01/21 更新: 2018/01/22 标题前增加 [Objective-C] 继承的概念 父类与子类 ●继承: 继承其他类 ●父类: 被继承的类 ...