Shichikuji and Power Grid
思路:一个很裸的最小生成树。把建立基站看成是,城市与源点(虚构的)建边。由此建立最小生成树,即可得出答案。
代码:
// Created by CAD on 2019/11/2.
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int maxn=2020*2000;
struct edge{
ll u,v;
ll w;
bool operator<(edge &e)
{
return w<e.w;
}
}e[maxn];
ll fa[2005],x[2005],y[2005],c[2005],k[2005];
int n;
vector<int> out1;
vector<pii> out2;
int find(int i)
{
return i==fa[i]?i:fa[i]=find(fa[i]);
}
int cnt=0;
int cnt1=0;
ll kruskal()
{
ll ans=0;
for(int i=0;i<=n;++i)
fa[i]=i;
for(int i=1;i<=cnt;++i)
{
int u=find(e[i].u),v=find(e[i].v);
if(u!=v)
{
ans+=e[i].w,fa[v]=u;
if(!e[i].u) out1.push_back(e[i].v);
else out2.push_back({e[i].u,e[i].v});
}
}
return ans;
}
int main()
{
// FOPEN;
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;++i)
cin>>x[i]>>y[i];
for(int i=1;i<=n;++i)
cin>>c[i];
for(int i=1;i<=n;++i)
cin>>k[i];
for(int i=1;i<=n;++i)
e[++cnt]=edge{0,i,c[i]};
for(int i=1;i<=n;++i)
for(int j=i+1;j<=n;++j)
e[++cnt]=edge{i,j,1ll*(abs(x[i]-x[j])+abs(y[i]-y[j]))*(k[i]+k[j])};
sort(e+1,e+cnt+1);
cout<<kruskal()<<endl;
cnt1=out1.size();
cout<<cnt1<<endl;
for(int i=0;i<cnt1-1;++i)
cout<<out1[i]<<" ";
if(cnt1)
cout<<out1[cnt1-1]<<endl;
cout<<out2.size()<<endl;
for(auto i:out2)
cout<<i.first<<" "<<i.second<<endl;
return 0;
}
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 ...
- CF1245D: Shichikuji and Power Grid
CF1245D: Shichikuji and Power Grid 题意描述: 给定\(n\)个点\((n\leq2000)\),在第\(i\)个点上建立一个基站需要\(c_i\)的代价,连接两个点 ...
- [Codeforces 1245D] Shichikuji and Power Grid (最小生成树)
[Codeforces 1245D] Shichikuji and Power Grid (最小生成树) 题面 有n个城市,坐标为\((x_i,y_i)\),还有两个系数\(c_i,k_i\).在每个 ...
- 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 1245 D. Shichikuji and Power Grid
传送门 经典的最小生成树模型 建一个点 $0$ ,向所有其他点 $x$ 连一条边权为 $c[x]$ 的边,其他任意两点之间连边,边权为 $(k_i+k_j)(\left | x_i-x_j\right ...
- CodeForces 1245D Shichikuji and Power Grid
cf题面 解题思路 比赛过程中想了一个贪心--把所有城市按照自建代价排序,排在第一的城市肯定自建,之后依次判断排在后面的城市要自建还是要连接前面的.这么做WA13了(第一次忘开long longWA4 ...
- 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 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; //坐标 ...
- Codeforces Round #597 (Div. 2)
A - Good ol' Numbers Coloring 题意:有无穷个格子,给定 \(a,b\) ,按以下规则染色: \(0\) 号格子白色:当 \(i\) 为正整数, \(i\) 号格子当 \( ...
随机推荐
- Java组合模式(思维导图)
图1 组合模式[点击查看图片] 1,以公司职员为例的结构 package com.cnblogs.mufasa.demo3; import java.util.ArrayList; import ja ...
- react 管理平台
https://open.vbill.cn/react-admin/ 开源中国:https://gitee.com/sxfad/react-admin.git GitHub:https://githu ...
- python 使用三种常用的工具包处理图片
matplotlib,PIL(Pillow),Opencv三种常用的作图方式. 使用matplotlib画图,很棒,matplotlib 是python最著名的2D绘图库,它提供了一整套和matlab ...
- LeetCode:178.分数排名
题目链接:https://leetcode-cn.com/problems/rank-scores/ 题目 编写一个 SQL 查询来实现分数排名.如果两个分数相同,则两个分数排名(Rank)相同.请注 ...
- 微信小程序中weui使用方法
1.git下载,找到dist文件: https://github.com/wechat-miniprogram/weui-miniprogram 2.把dist文件中的style复制到根目录 app. ...
- vue学习(7)-路由抽离
cnpm i vue-router -S
- Django—model系统:ORM之其他骚操作
Django ORM执行原生SQL # extra # 在QuerySet的基础上继续执行子语句 # extra(self, select=None, where=None, params=None, ...
- 万能模拟器eve-ng介绍
作为一名网络工程师,通过模拟器来搭建实验环境是必不可少的,主流的网络模拟器有如下几款:Packet Tracer是思科公司出的一款模拟器,只能模拟思科自己的设备,由于此款软件是纯软件模拟,所以思科设备 ...
- Kubernetes的yaml文件中command的使用
前面说了init容器initContainers,这主要是为应用容器做前期准备工作的,一般都会用到shell脚本,这就会用到command,这里写写command的用法. command就是将命令在创 ...
- 十九,基于helm搭建EFK日志收集系统
目录 EFK日志系统 一,EFK日志系统简介: 二,EFK系统部署 1,EFK系统部署方式 2,基于Helm方式部署EFK EFK日志系统 一,EFK日志系统简介: 关于系统日志收集处理方案,其实有很 ...