hdu 4463 Outlets(最小生成树)
Outlets
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 39 Accepted Submission(s) : 26
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
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.
Input
Output
Sample Input
4
2 3
0 0
1 0
0 -1
1 -1
0
Sample Output
3.41
#include <iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cmath>
using namespace std; double sum;
int i,j,n;
bool vis[];
int x[],y[];
double dis[],mp[][];
void prim()
{
for(int i=;i<n-;i++)
{
double minn=INT_MAX*1.0;
int k;
for(int j=;j<=n;j++)
if (!vis[j] && dis[j]<minn)
{
k=j;
minn=dis[j];
}
vis[k]=;
sum+=minn;
for(int j=;j<=n;j++)
if (!vis[j] && mp[k][j]<dis[j]) dis[j]=mp[k][j];
}
return;
}
int main()
{
while(scanf("%d",&n) && n)
{
int u,v;
memset(vis,,sizeof(vis));
scanf("%d%d",&u,&v);
for(i=;i<=n;i++)
scanf("%d%d",&x[i],&y[i]);
for(i=;i<=n;i++)
for(j=i+;j<=n;j++)
{
double d=sqrt(pow(x[i]-x[j],)+pow(y[i]-y[j],));
mp[i][j]=d;
mp[j][i]=d;
}
sum=mp[u][v];//先把那两家店连起来
vis[u]=;
vis[v]=; //全部标记走过
for(i=;i<=n;i++) dis[i]=mp[u][i];
for(i=;i<=n;i++) dis[i]=min(dis[i],mp[v][i]);//预处理到其他点的距离
prim();
printf("%.2lf\n",sum);
}
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】最小生成树(prim,kruscal都可)
以(x,y)坐标的形式给出n个点,修建若干条路使得所有点连通(其中有两个给出的特殊点必须相邻),求所有路的总长度的最小值. 因对所修的路的形状没有限制,所以可看成带权无向完全图,边权值为两点间距离.因 ...
- HDU 4463 Outlets(最小生成树给坐标)
Problem Description In China, foreign brand commodities are often much more expensive than abroad. T ...
- 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& ...
随机推荐
- wuzhi 五指 基本知识
参数:m 模块 在于 /coreframe/app/模块文件夹 |默认 content f php文件 控制器 在于/coreframe/app/模块 /文件.php | 默认 index v ...
- MC- 交易并设置止损
using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; using ATCenterP ...
- 【Loadrunner】初学Loadrunner——安装
一.准备工作 1.下载Loadrunner可以参考网上百度得到的可以在下面这个地址下载,比较大,4G左右 http://www.genilogix.com/downloads/loadrunner/l ...
- 一些牛人分享的ios技巧,保留着
摘要:记录一些网上非常牛的人写的博文.收藏起来. 以备日后需要时学习备用. 1:iOS中UIWebView的Javascript与Objective-C通信 http://imchao.net/201 ...
- PHP CURL 代理发送数据
$session = curl_init($request); curl_setopt ($session, CURLOPT_PROXY, $proxy); curl_setopt ($session ...
- Win7/Win8右键菜单管理工具(Easy Context Menu) v1.5 绿色版
软件名称: Win7/Win8右键菜单管理工具(Easy Context Menu)软件语言: 简体中文授权方式: 免费软件运行环境: Win8 / Win7 / Vista / WinXP软件大小: ...
- 201312月CCF-2,ISBN号码分析
明天要考CCF啦,偶还是很紧张的.最近看了数据结构,今天才开始上机练习,对,我就是这么懒..废话不多说,我写这篇文章主要是分析CCF编程的小窍门,因为在网上没找到,所以我决定自力更生丰衣足食.!!!! ...
- div盒子水平垂直居中的方法
这个问题比较老,方法比较多,各有优劣,着情使用. 一.盒子没有固定的宽和高 方案1.Transforms 变形 这是最简单的方法,不仅能实现绝对居中同样的效果,也支持联合可变高度方式使用.内容块定义t ...
- Python 查找binlog文件
经常需要在 binlog 中查找一些日志信息,于是写了一个简单的脚本.对于非常巨大的 binlog 文件,该脚本可能会速度慢,毕竟还是用的 list,暂时没想到好办法. 详细看代码: #/usr/bi ...
- 【JQuery的选择器】
一.基本选择器 基本选择器是JQuery中最常用的选择器,也是最简单的选择器,它通过元素的id,class和标签名来查找DOM元素(在网页中id只能使用一次,class允许重复使用). 选择器 描述 ...