HDU 4463 Outlets(最小生成树给坐标)
So when we Chinese go abroad, one of our most favorite activities is shopping in outlets. Some people buy tens of famous brand shoes and bags one time. In Las Vegas, the existing outlets can't match the demand of Chinese. So they want to build a new outlets in the desert. The new outlets consists of many stores. All stores are connected by roads. They want to minimize the total road length. The owner of the outlets just hired a data mining expert, and the expert told him that Nike store and Apple store must be directly connected by a road. Now please help him figure out how to minimize the total road length under this condition. A store can be considered as a point and a road is a line segment connecting two stores.
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<math.h>
using namespace std; int fa[]; struct node
{
int u,v;
double c;
}a[]; struct point
{
double x,y;
}Point[]; bool cmp(node b,node d)
{
return b.c<d.c;
} int find(int t)
{
return fa[t]==t ? t:fa[t]=find(fa[t]);
} double dis(point b,point d)
{
double res;
res=sqrt((b.x-d.x)*(b.x-d.x)+(b.y-d.y)*(b.y-d.y));
return res;
} int main()
{ int n,m;
double ans;
int p,q;
while(~scanf("%d",&n)&&n)
{
ans=0.0;
m=;
scanf("%d%d",&p,&q);
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&Point[i].x,&Point[i].y);
}
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
{
a[m].u=i;
a[m].v=j;
a[m++].c=dis(Point[i],Point[j]);
}
sort(a,a+m,cmp);
for(int i=;i<=n;i++)
fa[i]=i;
fa[p]=q;
ans+=dis(Point[p],Point[q]);
for(int i=;i<m;i++)
{
int p1=find(a[i].u),q1=find(a[i].v);
if(p1!=q1)
{
fa[p1]=q1;
ans+=a[i].c;
}
}
printf("%.2lf\n",ans); }
return ;
}
HDU 4463 Outlets(最小生成树给坐标)的更多相关文章
- HDU—4463 Outlets 最小生成树
In China, foreign brand commodities are often much more expensive than abroad. The main reason is th ...
- hdu 4463 Outlets(最小生成树)
Outlets Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submi ...
- 【HDU 4463 Outlets】最小生成树(prim,kruscal都可)
以(x,y)坐标的形式给出n个点,修建若干条路使得所有点连通(其中有两个给出的特殊点必须相邻),求所有路的总长度的最小值. 因对所修的路的形状没有限制,所以可看成带权无向完全图,边权值为两点间距离.因 ...
- HDU 4463 Outlets (最小生成树)
题意:给定n个点坐标,并且两个点已经连接,但是其他的都没有连接,但是要找出一条最短的路走过所有的点,并且路线最短. 析:这个想仔细想想,就是应该是最小生成树,把所有两点都可以连接的当作边,然后按最小生 ...
- HDU 4463 Outlets 【最小生成树】
<题目链接> 题目大意: 给你一些点的坐标,要求你将这些点全部连起来,但是必须要包含某一条特殊的边,问你连起这些点的总最短距离是多少. 解题分析: 因为一定要包含那条边,我们就记录下那条边 ...
- hdu 4463 Outlets(最小生成树)
题意:n个点修路,要求总长度最小,但是有两个点p.q必须相连 思路:完全图,prim算法的效率取决于节点数,适用于稠密图.用prim求解. p.q间距离设为0即可,最后输出时加上p.q间的距离 pri ...
- hdu 4463 Outlets
#include<bits/stdc++.h> using namespace std; double x[100+5],y[100+5]; double e[100+5][100+5]; ...
- hdu Constructing Roads (最小生成树)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1102 /************************************************* ...
- hdu 4463 第37届ACM/ICPC杭州赛区K题 最小生成树
题意:给坐标系上的一些点,其中有两个点已经连了一条边,求最小生成树的值 将已连接的两点权值置为0,这样一定能加入最小生成树里 最后的结果加上这两点的距离即为所求 #include<cstdio& ...
随机推荐
- 发送http请求,get和post两种请求方式
GET请求 GetMethod getMethod=null; String datas = "json=" + plain; HttpClient httpClient = ne ...
- Homebrew 安装mysql
在mac上安装软件,无疑安装一个brew是个很好的选择,关于brew是什么,怎么安装建议去brew官网查看, 附上地址:brew官网 还有一篇博文 http://www.cnblogs.com/xd ...
- Hadoop介绍-1.基本原理
了解大数据 首先,搞清楚hadoop在处理大数据的定位在哪里 什么是大数据?为什么要处理大数据? 数据量大(Volume) 数据类别复杂(Variety) 数据处理速度快(Velocity) 数据真实 ...
- Homebrew 备忘
每次都搜,写篇博客记录以备后续查看. 安装 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew ...
- 检测用户命令序列异常——使用LSTM分类算法【使用朴素贝叶斯,类似垃圾邮件分类的做法也可以,将命令序列看成是垃圾邮件】
通过 搜集 Linux 服务器 的 bash 操作 日志, 通过 训练 识别 出 特定 用户 的 操作 习惯, 然后 进一步 识别 出 异常 操作 行为. 使用 SEA 数据 集 涵盖 70 多个 U ...
- ftp主动模式与被动模式交互过程分析
1.相关介绍 1.1主动模式和被动模式 主动模式:服务端通过指定的数据传输端口(默认20),主动连接客户端提交的端口,向客户端发送数据. 被动模式:服务端采用客户端建议使用被动模式,开启数据传输端口的 ...
- xmanager运行报错:bash: /usr/bin/xterm: No such file or directory
1.原因 xterm没有安装,解决办法是下载然后安装即可. 如果机器可以用yum,则直接使用yum安装xterm即可: yum install -y xterm 如果没有网络,则在某台操作系统大版本相 ...
- weblogic创建domain教程
1.创建domain [ls@ls ~]$ cd /weblogic/wlserver_10.3/common/bin/ #进入创建文件所在目录 [ls@ls bin]$ ./config.sh #执 ...
- weblogic相关
来源:http://zhidao.baidu.com/link?url=gqPaYovGiEHYPPPyI6PgPV6THVLr4nlj3CGCjY3mwm0-ERUnfuQz614ywAwYLnP6 ...
- java中super关键字的用法
class Sum { int n; float f() { float sum=0; for(int i=1;i<=n;i++) sum=sum+i; System.out.println(& ...