解题报告

题目传送门

题意:

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

思路:

存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费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. yes---重复输出指定的字符串

    yes命令在命令行中输出指定的字符串,直到yes进程被杀死.不带任何参数输入yes命令默认的字符串就是y. 语法 yes(参数) 参数 字符串:指定要重复打印的字符串. 实例 [root@localh ...

  2. [HNOI2018]爆零记

    Day 0 完全不知道做什么. 打了一个splay板子,还没调出来emmmmm 不想做题目,最后做的一题是[HNOI2016]的超(sha)难(bi)题网络. 当我希望省选能出一下树剖时,旁边的大佬跟 ...

  3. glEnable(GL_DEPTH_TEST)作用

    glEnable(GL_DEPTH_TEST): 用来开启更新深度缓冲区的功能,也就是,如果通过比较后深度值发生变化了,会进行更新深度缓冲区的操作.启动它,OpenGL就可以跟踪再Z轴上的像素,这样, ...

  4. POJ3904 Sky Code【容斥原理】

    题目链接: http://poj.org/problem?id=3904 题目大意: 给你N个整数.从这N个数中选择4个数,使得这四个数的公约数为1.求满足条件的 四元组个数. 解题思路: 四个数的公 ...

  5. iOS开发系列之四 - UITextView 使用方法小结

    // 初始化输入框并设置位置和大小 UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 10, 300, 1 ...

  6. 如何在IDEA中创建web项目并且部署到Tomcat中

    步骤1:File->New Project, 步骤2:选择Project SDK为1.7 -> Next -> Finish(JDK)我自己的是1.7(这里的project,跟ecl ...

  7. quartz 持久化 数据库表

    此处只包括配置数据库操作 quartz 持久化数据库表格字段解释建表,SQL语句在dbTables文件夹中可以找到,介绍下我们开发主要使用到的表: (版本不一样,可能数据库表也不一样,这里使用2.2. ...

  8. POJ 2436 二进制枚举

    题意: 思路: 拆成二进制枚举 有哪个病毒在 判一判 就好了 //By SiriusRen #include <cstdio> #include <cstring> #incl ...

  9. mybatis+springmvc+sqlite一个累心的问题:不在纠结

    1 java.sql.SQLException: NYI 2 org.sqlite.RS.getColumnClassName(RS.java:269) 在配置mybatis+springmvc+sq ...

  10. 解析position定位

    关于position定位(所有主流浏览器都支持 position 属性),大家会联想到relative和absolute,下面我就讲一下relative和absolute分别是相对于谁进行定位的? 在 ...