D. Shichikuji and Power Grid

参考:Codeforces Round #597 (Div. 2)

思路:一个很裸的最小生成树。把建立基站看成是,城市与源点(虚构的)建边。由此建立最小生成树,即可得出答案。

代码:

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

  1. 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 ...

  2. CF1245D: Shichikuji and Power Grid

    CF1245D: Shichikuji and Power Grid 题意描述: 给定\(n\)个点\((n\leq2000)\),在第\(i\)个点上建立一个基站需要\(c_i\)的代价,连接两个点 ...

  3. [Codeforces 1245D] Shichikuji and Power Grid (最小生成树)

    [Codeforces 1245D] Shichikuji and Power Grid (最小生成树) 题面 有n个城市,坐标为\((x_i,y_i)\),还有两个系数\(c_i,k_i\).在每个 ...

  4. 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 ...

  5. Codeforces 1245 D. Shichikuji and Power Grid

    传送门 经典的最小生成树模型 建一个点 $0$ ,向所有其他点 $x$ 连一条边权为 $c[x]$ 的边,其他任意两点之间连边,边权为 $(k_i+k_j)(\left | x_i-x_j\right ...

  6. CodeForces 1245D Shichikuji and Power Grid

    cf题面 解题思路 比赛过程中想了一个贪心--把所有城市按照自建代价排序,排在第一的城市肯定自建,之后依次判断排在后面的城市要自建还是要连接前面的.这么做WA13了(第一次忘开long longWA4 ...

  7. Codeforces Round #597 (Div. 2) D. Shichikuji and Power Grid 题解 最小生成树

    题目链接:https://codeforces.com/contest/1245/problem/D 题目大意: 平面上有n座城市,第i座城市的坐标是 \(x[i], y[i]\) , 你现在要给n城 ...

  8. 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; //坐标 ...

  9. Codeforces Round #597 (Div. 2)

    A - Good ol' Numbers Coloring 题意:有无穷个格子,给定 \(a,b\) ,按以下规则染色: \(0\) 号格子白色:当 \(i\) 为正整数, \(i\) 号格子当 \( ...

随机推荐

  1. Kali Linux安装AWVS漏扫工具

    Acunetix是全球排名前三的漏洞发现厂商,其全称(Acunetix Web Vulnerability Scanner)AWVS是业内领先的网络漏洞扫描器,其被广泛赞誉为包括最先进的SQL注入和X ...

  2. element-ui当中table组件的合并行和列的属性:span-method的用法

    背景 最近基本上都是以Vue来构建项目,而UI框架也基本上都是使用的element-ui,所以里面组件用的也是越来越多,今天想记录的是非常非常小的一个属性的用法. Table组件 Table组件用了真 ...

  3. 【原创】大叔经验分享(83)impala执行多个select distinct

    impala在一个select中执行多个count distinct时会报错,比如执行 select key, count(distinct column_a), count(distinct col ...

  4. Lua的栈及基本栈操作

    Lua的栈及基本栈操作 https://blog.csdn.net/mydriverc2/article/details/51134737 https://blog.csdn.net/mydriver ...

  5. c++11 常量表达式

    c++11 常量表达式 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #inclu ...

  6. 【PR笔记】一、打造希区柯克变焦效果

    1. 导入素材,“链接选择项”关闭,删除音频 2. 添加效果--视频效果--扭曲--视频稳定器, 然后程序帮我们自动稳定 3.视频首尾添加关键帧,首帧缩放200%  尾帧不变, 使视频前后的主体大小差 ...

  7. 利用浏览器做好数字进制和ASCII码及Unicode教与学

    浏览器是现在个人计算机的标配,一般来说一个PC至少安装一种以上的浏览器.主流网页浏览器有Google Chrome.Internet Explorer.Microsoft Edge.Mozilla F ...

  8. weblogic 反序列化漏洞 getshell

    上传cmd.jsp,效果: 上传马:

  9. LLVM新建全局变量

    在LLVM中,有原生的AST Clone,却没有一个比较好的Stmt copy功能,基于Scout在LLVM上进行的修改,我们实现了自己的Stmt Clone功能. 要进行Stmt Clone,肯定需 ...

  10. 嵌入式安装telnet

    busybox配置 Defined at networking/Config.in:784 Depends on: TELNET Location: -> Networking Utilitie ...