思路:最短路,map[i][j] = d*(|x[i]-x[j]| + |y[i]-y[j]|) - add[i]


#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的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

随机推荐

  1. jQuery 1.7以后 jQuery2 新元素绑定事件on替代live

    最近做了一个类别动态加载的功能,jQuery版本用的是2.02. 绑定事件jQuery1.7之前用的是live或者是bind.新版的jQuery新增了on方法 由于子类别是动态加载的,默认是不会有事件 ...

  2. mouseover与mouseenter与mousemove的区别mouseout与mouseleave的区别

    <html> <head> <title></title> </head> <body> <p> 当鼠标进入div1 ...

  3. 判断浏览器是否支持某个css3属性的javascript方法

    判断浏览器是否支持css3某个属性的方法: /** * 判断浏览器是否支持某一个CSS3属性 * @param {String} 属性名称 * @return {Boolean} true/false ...

  4. PHP 透明水印生成代码

    PHP 透明水印生成代码,需要的朋友可以参考下. 复制代码代码如下: <?php  /*  * Created on 2010-10-27  * BY QQ542900563  * Copyri ...

  5. css实现div块半透明

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. php 删除文件夹及文件

    <?php function deleteDir($dir) { if (!$handle = @opendir($dir)) { return false; } while (false != ...

  7. 安装Android Studio报failed to find java version for 'C:\windows\system32\java.exe':[2] The system cannot find the specified file.错误的解决方案

    方案很简单,找到SYSTEM32目录下的java.exe文件,重命名为java.exe.orj. 方案出处:http://stackoverflow.com/questions/10339679/an ...

  8. 升级mac中的系统之后,给PHP安装扩展常出现问题

    (1)在装mcrypt插件时报错,提示:mcrypt fatal error: 'php.h' file not found,然后又仔细操作了一次在输完phpize回车时就已经开始出错了,出错信息如下 ...

  9. Oracle---->基本DDL

    修改表名: rename table_name1 to table_name2; delete [from] persons where lastname= 'Wilson';

  10. FZU 2140 Forever 0.5

     Problem 2140 Forever 0.5 Accept: 36    Submit: 113    Special JudgeTime Limit: 1000 mSec    Memory ...