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只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- 小shell函数
whoport() { port=$1 echo "------ who occupied port: $port ----------" info=$(sudo lsof ...
- php新特性--持续更新
命名空间 在其他语言中不算新鲜事,但php是5.3.0中引入,具体定义就不复述了,其主要作用是 封装和组织相关php类 .命名空间被引入之前php主要是通过Zend方式组织代码,这种方式带来的问题是类 ...
- Django视图与网址传参
目的:采用/add?a=1&b=2 这样get/post方法进行 修改一下mysite/views.py文件 from django.shortcuts import renderfrom ...
- CRF图像语义分割
看了Ladicky的文章Associative Hierarchical CRFs for Object Class Image Segmentation,下载他主页的代码,文章是清楚了,但代码的RE ...
- Python复杂多重排序
1. cmp函数是python自带的函数,用于比较两个参数哪个大哪个小 print cmp(2, 3) # -1 如果第一个参数比第二个小,就返回-1,两个元素相等,返回0,否则返回1 2.所以就可以 ...
- poj 2342 Anniversary party 树形DP入门
题目链接:http://poj.org/problem?id=2342 题意:一家公司有1 <= N <= 6 000个职工,现要组织一些职工参加晚会,要求每个职工和其顶头上司不能同时参加 ...
- Sublime Text 3之Package Control 安装
1.通过快捷键 ctrl+` 或者 View > Show Console 打开控制台,然后粘贴以下安装代码: import urllib.request,os; pf = 'Package C ...
- 数据结构———重载与模板(C++)
相关信息 /* * * @subject 数据结构 * @author 信管1142班 201411671210 JJ lai * * @program 模板与重载 * */ 实验一: /* 要求如下 ...
- jQuery滑动导航菜单
js: $(function(){ $("ul.sub").parent().append("<span></span>"); $(&q ...
- Unity3D研究院之在把代码混淆过的游戏返混淆回来
最近一直在找如何在MAC上混淆Android的DLL,至今没能找到合适的,有大神知道记得告诉我喔.今天群里有人说了一个混淆代码和返混淆代码的工具de4dot ,不查不知道一查吓一跳.这玩意可以把别人混 ...