UVa10397_Connect the Campus(最小生成树)(小白书图论专题)
解题报告
题意:
使得学校网络互通的最小花费,一些楼的线路已经有了。
思路:
存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费0,求最小生成树
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define inf 0x3f3f3f3f
using namespace std;
int n,m,_hash[1110][1110],vis[1100];
double mmap[1110][1110],dis[1100];
struct node {
double x,y;
} p[1110];
double disc(node p1,node p2) {
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
void prime() {
for(int i=0; i<n; i++) {
dis[i]=mmap[0][i];
vis[i]=0;
}
double minn=(double )inf,ans=0;
int u;
dis[0]=0;
vis[0]=1;
for(int i=0; i<n-1; i++) {
minn=inf;
for(int j=0; j<n; j++) {
if(!vis[j]&&dis[j]<minn) {
minn=dis[j];
u=j;
}
}
ans+=minn;
vis[u]=1;
for(int j=0; j<n; j++) {
if(!vis[j]&&mmap[u][j]<dis[j]) {
dis[j]=mmap[u][j];
}
}
}
printf("%.2lf\n",ans);
}
int main() {
int i,j,u,v,w,k=1;
while(~scanf("%d",&n)) {
for(i=0; i<n; i++) {
for(j=0; j<n; j++)
mmap[i][j]=(double)inf;
mmap[i][i]=0;
}
for(i=0; i<n; i++) {
scanf("%lf%lf",&p[i].x,&p[i].y);
}
for(i=0; i<n; i++) {
for(j=0; j<n; j++) {
mmap[i][j]=disc(p[i],p[j]);
}
}
scanf("%d",&m);
while(m--) {
scanf("%d%d",&u,&v);
mmap[u-1][v-1]=mmap[v-1][u-1]=0;
}
prime();
}
return 0;
}
Connect the Campus
Input: standard input
Output: standard output
Time Limit: 2 seconds
Many new buildings are under construction on the campus of the University of Waterloo. The university has hired bricklayers, electricians, plumbers, and a computer programmer. A computer programmer? Yes, you have been hired to ensure that each building is
connected to every other building (directly or indirectly) through the campus network of communication cables.
We will treat each building as a point specified by an x-coordinate and a y-coordinate. Each communication cable connects exactly two buildings, following a straight line between the buildings. Information travels along a cable in both directions. Cables
can freely cross each other, but they are only connected together at their endpoints (at buildings).
You have been given a campus map which shows the locations of all buildings and existing communication cables. You must not alter the existing cables. Determine where to install new communication cables so that all buildings are connected. Of course, the
university wants you to minimize the amount of new cable that you use.
Fig: University of Waterloo Campus
Input
The input file describes several test case. The description of each test case is given below:
The first line of each test case contains the number of buildings N (1<=N<=750). The buildings are labeled from 1 to N. The next Nlines give the x and y coordinates
of the buildings. These coordinates are integers with absolute values at most 10000. No two buildings occupy the same point. After that there is a line containing the number of existing cables M (0 <= M <= 1000) followed byM lines
describing the existing cables. Each cable is represented by two integers: the building numbers which are directly connected by the cable. There is at most one cable directly connecting each pair of buildings.
Output
For each set of input, output in a single line the total length of the new cables that you plan to use, rounded to two decimal places.
Sample Input
4
103 104
104 100
104 103
100 100
1
4 2
4
103 104
104 100
104 103
100 100
1
4 2
Sample Output
4.41
4.41
UVa10397_Connect the Campus(最小生成树)(小白书图论专题)的更多相关文章
- UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)
解题报告 题意: 有一个旅游团如今去出游玩,如今有n个城市,m条路.因为每一条路上面规定了最多可以通过的人数,如今想问这个旅游团人数已知的情况下最少须要运送几趟 思路: 求出发点到终点全部路其中最小值 ...
- UVa753/POJ1087_A Plug for UNIX(网络流最大流)(小白书图论专题)
解题报告 题意: n个插头m个设备k种转换器.求有多少设备无法插入. 思路: 定义源点和汇点,源点和设备相连,容量为1. 汇点和插头相连,容量也为1. 插头和设备相连,容量也为1. 可转换插头相连,容 ...
- UVa567_Risk(最短路)(小白书图论专题)
解题报告 option=com_onlinejudge&Itemid=8&category=7&page=show_problem&problem=508"& ...
- UVa10048_Audiophobia(最短路/floyd)(小白书图论专题)
解题报告 题意: 求全部路中最大分贝最小的路. 思路: 类似floyd算法的思想.u->v能够有另外一点k.通过u->k->v来走,拿u->k和k->v的最大值和u-&g ...
- UVa563_Crimewave(网络流/最大流)(小白书图论专题)
解题报告 思路: 要求抢劫银行的伙伴(想了N多名词来形容,强盗,贼匪,小偷,sad.都认为不合适)不在同一个路口相碰面,能够把点拆成两个点,一个入点.一个出点. 再设计源点s连向银行位置.再矩阵外围套 ...
- UVa409_Excuses, Excuses!(小白书字符串专题)
解题报告 题意: 找包括单词最多的串.有多个按顺序输出 思路: 字典树爆. #include <cstdio> #include <cstring> #include < ...
- 正睿OI国庆DAY2:图论专题
正睿OI国庆DAY2:图论专题 dfs/例题 判断无向图之间是否存在至少三条点不相交的简单路径 一个想法是最大流(后来说可以做,但是是多项式时间做法 旁边GavinZheng神仙在谈最小生成树 陈主力 ...
- UVA 571 Jugs ADD18 小白书10 数学Part1 专题
只能往一个方向倒,如c1=3,c2=5,a b从0 0->0 5->3 2->0 2->2 0->2 5->3 4->0 4->3 1->0 1- ...
- Django框架详细介绍---ORM---图书信息系统专题训练
from django.db import models # Create your models here. # 书 class Book(models.Model): title = models ...
随机推荐
- Mac系统下安装pip
Mac下 pip的安装 编译 Python3.7 终端输入: curl https://bootstrap.pypa.io/get-pip.py | python3 1 安装完成,检查版本信息 pip ...
- ArcGIS api for javascript——加入地图并显示当前地图范围
描述 这个示例使用Map.extent property属性接收地图范围的左下角和右上角坐标 "书签". 使用下列行创建地图: var map = new esri.Map(&qu ...
- Looger级别
Logger级别 日志记录器(Logger)是日志处理的核心组件.log4j具有5种正常级别(Level).日志记录器(Logger)的可用级别Level (不包括自定义级别 Level), 以下内容 ...
- Qt 5.3 下OpenCV 2.4.11 开发(0)图像处理基本概念
1.普通情况下的RGB彩色图像:它的每一个像素点都是由三个通道组成,即红色(R).绿色(G)和蓝色(B).8位三通道彩色图像就是每一个像素中每一个通道的取值范围都是 0~255(即二进制下的8位数), ...
- 在启动php时,无法启动此程序,由于计算机中丢失MSVCR110.dll的解决方法
在启动php时,运行RunHiddenconsole.exe php-cgi.exe -b 127.0.0.1:9000 -c时,出现错误:无法启动此程序,由于计算机中丢失MSVCR110.dll 方 ...
- Kinect for Windows V2 SDK+ VS2012 环境搭建
眼下使用的SDK版本号是KinectSDK-v2.0-PublicPreview1409-Setup.exe. 下载地址:http://www.microsoft.com/en-us/download ...
- Go 语言编程
[课程名称]Go 语言编程 [课程时间]2014年7月30日(周三) 20:50 - 22:00 [课程安排]20:50-21:00 通过邮件地址登录网络课堂 ...
- .Net 路由处理厉害了
通过设置路由,可以灵活的显示地址内容.它会自动转换为想要的控制器和方法中去. using System; using System.Collections.Generic; using System. ...
- POSTGRESQL NO TABLE
POSTGRESQL EXTENDING SQL GRIGGER PROCEDURAL
- vue中剖析中的一些方法
1 判断属性 71 -81 var hasOwnProperty = Object.prototype.hasOwnProperty; /** * Check whether the object h ...