解题报告

题目传送门

题意:

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

思路:

存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费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(最小生成树)(小白书图论专题)的更多相关文章

  1. UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)

    解题报告 题意: 有一个旅游团如今去出游玩,如今有n个城市,m条路.因为每一条路上面规定了最多可以通过的人数,如今想问这个旅游团人数已知的情况下最少须要运送几趟 思路: 求出发点到终点全部路其中最小值 ...

  2. UVa753/POJ1087_A Plug for UNIX(网络流最大流)(小白书图论专题)

    解题报告 题意: n个插头m个设备k种转换器.求有多少设备无法插入. 思路: 定义源点和汇点,源点和设备相连,容量为1. 汇点和插头相连,容量也为1. 插头和设备相连,容量也为1. 可转换插头相连,容 ...

  3. UVa567_Risk(最短路)(小白书图论专题)

    解题报告 option=com_onlinejudge&Itemid=8&category=7&page=show_problem&problem=508"& ...

  4. UVa10048_Audiophobia(最短路/floyd)(小白书图论专题)

    解题报告 题意: 求全部路中最大分贝最小的路. 思路: 类似floyd算法的思想.u->v能够有另外一点k.通过u->k->v来走,拿u->k和k->v的最大值和u-&g ...

  5. UVa563_Crimewave(网络流/最大流)(小白书图论专题)

    解题报告 思路: 要求抢劫银行的伙伴(想了N多名词来形容,强盗,贼匪,小偷,sad.都认为不合适)不在同一个路口相碰面,能够把点拆成两个点,一个入点.一个出点. 再设计源点s连向银行位置.再矩阵外围套 ...

  6. UVa409_Excuses, Excuses!(小白书字符串专题)

    解题报告 题意: 找包括单词最多的串.有多个按顺序输出 思路: 字典树爆. #include <cstdio> #include <cstring> #include < ...

  7. 正睿OI国庆DAY2:图论专题

    正睿OI国庆DAY2:图论专题 dfs/例题 判断无向图之间是否存在至少三条点不相交的简单路径 一个想法是最大流(后来说可以做,但是是多项式时间做法 旁边GavinZheng神仙在谈最小生成树 陈主力 ...

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

  9. Django框架详细介绍---ORM---图书信息系统专题训练

    from django.db import models # Create your models here. # 书 class Book(models.Model): title = models ...

随机推荐

  1. 紫书 习题 10-6 UVa 1210(前缀和)

    素数筛然后前缀和 看代码 #include<cstdio> #include<vector> #include<cstring> #include<map&g ...

  2. python中的装饰器decorator

    python中的装饰器 装饰器是为了解决以下描述的问题而产生的方法 我们在已有的函数代码的基础上,想要动态的为这个函数增加功能而又不改变原函数的代码 例如有三个函数: def f1(x): retur ...

  3. POJ 3863 Business Center

    Business Center Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Origina ...

  4. ArcGIS api for javascript——地理处理任务-瓶中信

    描述 如果在海洋中丢下一个瓶子,本例使用颗粒追踪模型显示指定的天数后瓶子在的地方.首先,输入一个追踪瓶子的天数.然后单击按钮并在海洋里的任意地方画一个点来开始模型.几秒以后将看到一条线出现描述瓶子将去 ...

  5. [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number

    Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...

  6. android 聊天室窗体

    public class MainActivity extends Activity { ScrollView scrollView; Button button; LinearLayout layo ...

  7. PIO Core

    PIO核概述 具有Avalon接口的并行输入/输出(parallel input/output - PIO)核,在Avalon存储器映射(Avalon Memory-Mapped Avalon-MM) ...

  8. android中文网站

    Google Developers中国网站发布 用户评价:  / 55 差好  最后更新于 2016年12月09日 点击数:15209   我们很高兴地宣布,Google Developers 中国网 ...

  9. 异常Exception

    try…catch…finally恐怕是大家再熟悉不过的语句了,而且感觉用起来也是很简单,逻辑上似乎也是很容易理解.不过,我亲自体验的“教训”告诉我,这个东西可不是想象中的那么简单.听话.不信?那你看 ...

  10. 37.微信跳一跳辅助开发(C语言+EasyX)

    一.开发环境 开发环境 使用语言:C/C++ IDE:VS2010+ 其他三方库 EasyX(http://www.easyx.cn/downloads/) ADB(链接:https://pan.ba ...