Codeforces 302D
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
long long int map[105][105],vis[105],dist[105],add[105];
int n,d;
void init()
{
memset(vis,0,sizeof(vis));
for(int i = 0; i < 105; i ++)
{
for(int j = 0; j < 105; j ++)
{
map[i][j] = 1 << 30;
}
}
return ;
} int main()
{
int x[105],y[105];
int ans,k;
//freopen("in.c","r",stdin);
while(~scanf("%d%d",&n,&d))
{
init();
for(int i = 2; i <= n-1; i ++)
scanf("%d",&add[i]);
for(int i = 1; i <= n; i ++)
scanf("%d%d",&x[i],&y[i]);
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= n; j ++)
map[i][j] = (abs(x[i] - x[j]) +abs(y[i] - y[j]))*d - add[i];
}
// for(int i = 1;i <= n;i ++)
// {
// for(int j = 1;j <= n;j ++)
// {if(i != j) printf("%d<-->%d == %d ",i,j,map[i][j]),printf("\n");}
// }
for(int i = 1;i <= n;i ++)
dist[i] = map[1][i];
ans = 0;
vis[1] = 1;
for(int i = 1;i <= n;i ++)
{
long long int min = 1 << 30;
for(int j = 1;j <= n;j ++)
{
if(!vis[j] && min > dist[j])
{
k = j;
min = dist[j];
}
}
vis[k] = 1;
for(int j = 1;j <= n;j ++)
{
if(!vis[j] && dist[j] > map[k][j] + dist[k])
dist[j] = map[k][j] +dist[k];
}
}
printf("%d\n",dist[n]);
}
return 0;
}
Codeforces 302D的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- Linux C 程序 字符串运算符-表达式(TWO)
1.字符串常量 双引号"" :eg:"china" ,字符串在存储的时候会以一个\0为结束标志.2.符号常量 ,给常量取一个名字. #include< ...
- thinkphp分页实现
以上为我对于thinkphp分页的实现效果,两种方法,一种调用公共函数中的函数方法(参考http://www.cnblogs.com/tianguook/p/4326613.html),一种是在模型中 ...
- PHP 生成随机浮点数
<?php /** * @desc 获取随机浮点数(支持最大最小值参数互换) * @date 2014-11-07 17:04:21 * * @param int|\最小浮点数 $min 最小浮 ...
- MySQL大数据量快速分页实现
一般刚开始学SQL语句的时候,会这样写 代码如下: SELECT * FROM table ORDER BY id LIMIT 1000, 10; 但在数据达到百万级的时候,这样写会慢死 代码如下: ...
- 温故知新——json
Json简介 Json(JavaScript Object Notation)是一种轻量级的数据交换格式.它是基于javascript(Standard ECMA-262 3rd Edition - ...
- 2014年辛星完全解读Javascript第二节
本小节我们讲解一下Javascript的语法,虽然js语言非常简单,它的语法也相对好学一些,但是不学总之还是不会的,因此,我们来一探究竟把. ********注释************* 1.我们通 ...
- Vm image download resource
http://vmdepot.msopentech.com/List/Index http://www.hanselman.com/blog/Over400VirtualMachineImagesOf ...
- Oracle登陆及修改用户密码
16:20 2013/7/7 Oracle 登陆 管理员登陆 sqlplus sys/root as sysdba (密码认证)这个root是安装数据库最初你输入的口令 sqlplus /as ...
- C# and JSON
JQuery Parse JSON var obj = $.parseJSON(data); C# creates JSON string: public static class JSONHelpe ...
- win10应用安装位置修改方法
win10应用安装位置怎么改?很多用户升级win10的系统之后,对于win10应用装置的位置如何修改一直不知道如何解决,今天,小编就跟大家一起来看看如何修改win10应用装置的位置. win10应用安 ...