codeforces Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid
#include<bits/stdc++.h>
using namespace std ;
int n;
struct City {
int id;
long long x,y; //坐标
long long cc,kk; //自建的花费,连线的花费
bool self;//是否建站
int fa;//连线的站
bool operator < (const City & a)const {
return cc<a.cc;
}
} c[];
int main() {
scanf("%d",&n);
for(int i=; i<=n; i++) {
c[i].id=i;//发电站编号
c[i].self=; //首先都默认是自建的
scanf("%lld%lld",&c[i].x,&c[i].y); //输入坐标
}
for(int i=; i<=n; i++) scanf("%lld",&c[i].cc); //初始都为自建
for(int i=; i<=n; i++) scanf("%lld",&c[i].kk);//连线
long long ans=,selfnum=;
for(int i=; i<=n; i++) {
sort(c+i,c++n);//大概就是要随时排序,每次找到最小的,每次排序要排除前一次的,防止多加费用
ans+=c[i].cc; //费用
if(c[i].self) selfnum++; //判断是否自建
for(int j=i+; j<=n; j++) {
long long cost=(c[i].kk+c[j].kk)*(abs(c[i].x-c[j].x)+abs(c[i].y-c[j].y));
if(cost<c[j].cc) {
c[j].cc=cost;
c[j].self=;//放弃自建,说要已经和别的站建立了联系
c[j].fa=c[i].id;
}
}
}
printf("%lld\n%lld\n",ans,selfnum);
for(int i=; i<=n; i++)
if(c[i].self) printf("%d ",c[i].id);
printf("\n%lld\n",n-selfnum);
for(int i=; i<=n; i++)
if(!c[i].self) printf("%d %d\n",c[i].id,c[i].fa);
return ;
}
/*首先假设每个点都自建,那么每个点的代价就是自建代价。
然后按照代价排序,用代价最小的点去更新后面那些点,
如果能更新用电代价,就把那些点连接到当前点。
然后进入下一轮循环,排除上一次代价最小的点,把剩下的点再次按照代价排序,
然后用这些点中代价最小的去更新其他的,以此类推。 */
codeforces Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid的更多相关文章
- Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid 最小生成树
D. Shichikuji and Power Grid</centerD.> Shichikuji is the new resident deity of the South Blac ...
- Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid
链接: https://codeforces.com/contest/1245/problem/D 题意: Shichikuji is the new resident deity of the So ...
- Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid 题解 最小生成树
题目链接:https://codeforces.com/contest/1245/problem/D 题目大意: 平面上有n座城市,第i座城市的坐标是 \(x[i], y[i]\) , 你现在要给n城 ...
- Codeforces Round #597 (Div. 2)
A - Good ol' Numbers Coloring 题意:有无穷个格子,给定 \(a,b\) ,按以下规则染色: \(0\) 号格子白色:当 \(i\) 为正整数, \(i\) 号格子当 \( ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
随机推荐
- VSCode添加git bash作为默认终端
VSC添加git bash作为默认终端的settings.json添加 { "terminal.integrated.shell.windows": "D:\\Progr ...
- FastDFS 单机部署指南
简介 FastDFS是一个开源的分布式文件系统,官方介绍有详细的介绍,不多赘述.本文主要是FastDFS的搭建及采坑指南. Step By Step Guide 系统 阿里云ECS Ubuntu 16 ...
- yii2 response响应配置
response参数配置 方式一.全局配置 用于接口开发 适用:只有所有请求都是application/json类型时可用. $config = [ 'components' => [ 'res ...
- with open()函数中,如何在文件名设置中引用变量(python)
name = "wangyang" age = " with open("C:/Users/mike1/Desktop/name_age.txt", ...
- windows密码抓取工具-mimikatz
前言 介绍一下windows的密码hash值的组成: Windows系统下的hash密码格式为:用户名称:RID:LM-HASH值:NT-HASH值,例如: Administrator::C8825D ...
- linux vi编辑器光标跳到文件末尾
1.:0,:1,gg都可以到第一行2.shift+g到末行3.或者:$=检查总行数比如24,:24到第24行
- Mybatis常见面试题汇总
Mybatis常见面试题汇总 最近在复习整理Mybatis的相关知识,针对面试中的典型问题,结合相关书籍和网上相关帖子,做如下整理. ================================= ...
- sqli-labs less-17 --> less-20
Less-17 (报错盲注) 参考资料1:https://www.cnblogs.com/AmoBlogs/p/8673748.html
- LayIM聊天框全屏根据浏览器高宽自适应
个人博客 地址:http://www.wenhaofan.com/article/20190410190628 问题 由于LayIM没有处理聊天框在全屏状态下根据浏览器缩放处理高宽,所以会导致在浏览器 ...
- CSS 美化网页元素
一.为什么使用CSS 1.有效的传递页面信息 2.使用CSS美化过的页面文本,使页面漂亮.美观,吸引用户 3.可以很好的突出页面的主题内容,使用户第一眼可以看到页面主要内容 4.具有良好的用户体验 二 ...