原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf

题解

给你平面上若干点,生成一颗完全图,让你生成一颗最小生成树。模板题。图中已经有了的边要将权值置0。代码是队友写的。

代码

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <bitset>
#define INF 1000000005
#define eps 1e-10
#define PI acos(-1.0)
#define K (0.017453292519943295769236907684886l)
#define LL long long
#define ULL unsigned long long using namespace std; const int maxn = ; double a[maxn][maxn], dist[maxn]; int n, pre[maxn], m, x[maxn], y[maxn], vis[maxn][maxn], flag[maxn]; double Get_dist(int s, int t)
{
return sqrt((x[s] - x[t]) * (x[s] - x[t]) + (y[s] - y[t]) * (y[s] - y[t]));
} int main()
{
scanf("%d", &n);
for (int i = ; i <= n; i++)
scanf("%d%d", &x[i], &y[i]);
memset(vis, , sizeof(vis));
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
a[i][j] = Get_dist(i, j);
scanf("%d", &m);
for (int i = ; i <= m; i++)
{
int u, v;
scanf("%d%d", &u, &v);
vis[u][v] = vis[v][u] = ;
a[u][v] = a[v][u] = ;
}
for (int i = ; i <= n; i++)
{
flag[i] = ;
dist[i] = a[][i];
pre[i] = ;
}
flag[] = ; pre[] = ;
for (int i = ; i < n; i++)
{
double minx = 1e30;
int p;
for (int j = ; j <= n; j++)
if (flag[j] && minx > dist[j])
{
minx = dist[j];
p = j;
}
if (!vis[p][pre[p]]) printf("%d %d\n", p, pre[p]);
flag[p] = ;
for (int j = ; j <= n; j++)
if (dist[j] > a[p][j])
{
dist[j] = a[p][j];
pre[j] = p;
}
}
return ;
}

Codeforces Gym 100203H Highways 最小生成树的更多相关文章

  1. Gym - 100203H Highways 最小生成树

    题意:平面上n个点修路,已经修好了m条,再修若干条使得点之间连通,求最小代价的方案. 思路:基本上是裸的最小生成树了,我这里存边直接存在multyset了,取的时候也比较方便,我本来就是这么考虑的,队 ...

  2. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  3. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  4. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

  5. 【Codeforces Gym 100725K】Key Insertion

    Codeforces Gym 100725K 题意:给定一个初始全0的序列,然后给\(n\)个查询,每一次调用\(Insert(L_i,i)\),其中\(Insert(L,K)\)表示在第L位插入K, ...

  6. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  7. codeforces gym 100553I

    codeforces gym 100553I solution 令a[i]表示位置i的船的编号 研究可以发现,应是从中间开始,往两边跳.... 于是就是一个点往两边的最长下降子序列之和减一 魔改树状数 ...

  8. CodeForces Gym 100213F Counterfeit Money

    CodeForces Gym题目页面传送门 有\(1\)个\(n1\times m1\)的字符矩阵\(a\)和\(1\)个\(n2\times m2\)的字符矩阵\(b\),求\(a,b\)的最大公共 ...

  9. Codeforces GYM 100876 J - Buying roads 题解

    Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...

随机推荐

  1. type和object

    一.定义 1.object是所有新式类的父类 2.type是所有类的类    二.解析   下面通过代码来比较一下object和type的关系(__class__获取所属的类,__bases__获取父 ...

  2. visual studio 2013 for windows desk报error MSB8020: The build tools for v141错误

    由于硬件限制,学习在touchgfx暂时在Windows下模拟仿真,了解其基本原理和有一个基本感性认识,因此安装了VS Express 2013 for Desktop轻量级编译器. 有TouchGF ...

  3. #ifndef、#def、#endif说明

    你所遇到的这几个宏是为了进行条件编译.一般情况下,源程序中所有的行都参加编译.但是有时希望对其中一部分内容只在满足一定条件才进行编译,也就是对一 部分内容指定编译的条件,这就是“条件编译”.有时,希望 ...

  4. 什么是Maven?

    Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. 发文时,绝大多数开发人员都把 Ant 当作 Java 编程项目的标准构建工具.遗憾的是, ...

  5. 大数据学习——scala数组

    package com import scala.collection.mutable.ArrayBuffer /** * Created by Administrator on 2019/4/8. ...

  6. python学习-- 在for循环中还有很多有用的东西,如下:

    变量 描述 forloop.counter 索引从 1 开始算 forloop.counter0 索引从 0 开始算 forloop.revcounter 索引从最大长度到 1 forloop.rev ...

  7. pg 创建自增id

    CREATE SEQUENCE original_site_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1; 先创 ...

  8. 为什么要用全文搜索引擎:全文搜索引擎 VS 数据库管理系统

    正文一:Full Text Search Engines vs. DBMS  发表于2009年 正文二:Elasticsearch - A High-Performance Full-Text Sea ...

  9. .net SignalR 聊天室

    代码地址:https://gitee.com/srnsrn/netSignalr.git 运行项目打开多个页面 私密聊天

  10. 【Kubernetes】The connection to the server <master>:6443 was refused - did you specify the right host or port?

    不知道怎么用着用着,使用kubectl 时报错,错误如下: root@R740--:~# kubectl get pod The connection to the server 107.105.13 ...