博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVa10397_Connect the Campus(最小生成树)(小白书图论专题)
阅读量:6906 次
发布时间:2019-06-27

本文共 2610 字,大约阅读时间需要 8 分钟。

解题报告

题意:

使得学校网络互通的最小花费,一些楼的线路已经有了。

思路:

存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费0,求最小生成树

#include 
#include
#include
#include
#define inf 0x3f3f3f3fusing 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

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

转载地址:http://ouldl.baihongyu.com/

你可能感兴趣的文章
Windows聚焦转为图片
查看>>
POJ NOI0101-09 字符菱形
查看>>
jQuery--停止动画和判断是否处于动画状态stop()
查看>>
iPhone 物理尺寸与分辨率
查看>>
win10系统下cmd输入一下安装的软件命令提示拒绝访问解决办法
查看>>
OpenJudge/Poj 1004 Financial Management
查看>>
面向服务(接口)开发过程中常用的实体类数据复制解决方案
查看>>
Scala 学习笔记之函数(3)
查看>>
Fiddler (二) Script 用法
查看>>
[转载] 信息系统项目管理师考试习题——整体管理
查看>>
LC 425 word squares
查看>>
Web框架之Django_08 重要组件(form组件、cookie和session组件)
查看>>
HDU 6103
查看>>
zookeeper 实现分布式锁
查看>>
sql server 数据修改不了的设计
查看>>
Reinforcement Learning by Sutton 第三章习题答案
查看>>
mysql tinyint
查看>>
UNIX网络编程——getsockname和getpeername函数
查看>>
Bad Request - Request Too Long
查看>>
sqlist
查看>>