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\) 号格子当 \( ...
随机推荐
- mysql数据库的锁表与解决办法(原博客url:http://www.cnblogs.com/wanghuaijun/p/5949934.html)
MySQL锁概述 相对其他数据库而言,MySQL的锁机制比较简单,其最显著的特点是不同的存储引擎支持不同的锁机制.比如,MyISAM和MEMORY存储引擎采用的是表级锁(table-level loc ...
- linux下mysql数据导入到redis
自Redis 2.6以上版本起,Redis支持快速大批量导入数据,即Pipe传输.通过将要导入的命令转换为Resp格式,然后通过MySQL的concat()来整理出最终导入的命令集合,以达到快速导入的 ...
- Unity 更改鼠标指针
1. 把鼠标指针图标导入到Unity中,把它的Texture Type改为Cursor : 2. 打开PlayerSettings面板,把鼠标指针图片拖到Default Cursor中: 3. 在场景 ...
- 基于PROMISE解决回调地狱问题
回调地狱问题: 在使用JavaScript时,为了实现某些逻辑经常会写出层层嵌套的回调函数,如果嵌套过多,会极大影响代码可读性和逻辑,这种情况也被成为回调地狱.比如说你要把一个函数 A 作为回调函数, ...
- struts访问jsp api内置对象的集中方式
1 default-action-ref元素改元素用来配置默认的action,如果struts找不到对应的action,就会调用这个默认的action 2 dmi处理方式是通过请求action中的一个 ...
- 关于写SQL语句的技巧
一.SQL总结写法 SQL的写法无非就是几种,关联查询,子查询,分组函数,各种函数的使用 1.首先根据要做的需求,先分析一下,需要用到哪些查询,例如要用到关联查询,就先把用到的表列出来,比如a,b,c ...
- C语言memset函数详解
C语言memset函数详解 memset() 的作用:在一段内存块中填充某个给定的值,通常用于数组初始化与数组清零. 它是直接操作内存空间,mem即“内存”(memory)的意思.该函数的原型为: # ...
- 手写走通HTTP server 第二版本
HTTP server 2.0 1 接收客户请求 2 解析客户端请求 3 组合数据,形成HTTP response 4 将数据发送给客户端 升级 : 1 多线程接收客户端请求 2 基本的请求解析,根据 ...
- redis系列二: linux下安装redis
下面介绍在Linux环境下,Redis的安装与配置 一. 安装 1.首先上官网下载Redis 压缩包,地址:http://redis.io/download 下载稳定版3.0即可. 2.通过远程管理工 ...
- centos能进入命令行界面,进不了图形界面
在开机引导界面按“e”, 找到linux16开头的一行,定位到ro然后修改ro为rw,并添加:init=/sysroot/bin/sh 使用ctrl x进入安全模式. 使用命令:chroot /sys ...