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

In China, foreign brand commodities are often much more expensive than abroad. The main reason is that we Chinese people tend to think foreign things are better and we are willing to pay much for them. The typical example is, on the United Airline flight, they give you Haagendazs ice cream for free, but in China, you will pay $10 to buy just a little cup.
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

There are several test cases. For each test case: The first line is an integer N( 3 <= N <= 50) , meaning there are N stores in the outlets. These N stores are numbered from 1 to N. The second line contains two integers p and q, indicating that the No. p store is a Nike store and the No. q store is an Apple store. Then N lines follow. The i-th line describes the position of the i-th store. The store position is represented by two integers x,y( -100<= x,y <= 100) , meaning that the coordinate of the store is (x,y). These N stores are all located at different place. The input ends by N = 0.

Output

For each test case, print the minimum total road length. The result should be rounded to 2 digits after decimal point.

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(最小生成树)的更多相关文章

  1. HDU—4463 Outlets 最小生成树

    In China, foreign brand commodities are often much more expensive than abroad. The main reason is th ...

  2. 【HDU 4463 Outlets】最小生成树(prim,kruscal都可)

    以(x,y)坐标的形式给出n个点,修建若干条路使得所有点连通(其中有两个给出的特殊点必须相邻),求所有路的总长度的最小值. 因对所修的路的形状没有限制,所以可看成带权无向完全图,边权值为两点间距离.因 ...

  3. HDU 4463 Outlets(最小生成树给坐标)

    Problem Description In China, foreign brand commodities are often much more expensive than abroad. T ...

  4. HDU 4463 Outlets (最小生成树)

    题意:给定n个点坐标,并且两个点已经连接,但是其他的都没有连接,但是要找出一条最短的路走过所有的点,并且路线最短. 析:这个想仔细想想,就是应该是最小生成树,把所有两点都可以连接的当作边,然后按最小生 ...

  5. HDU 4463 Outlets 【最小生成树】

    <题目链接> 题目大意: 给你一些点的坐标,要求你将这些点全部连起来,但是必须要包含某一条特殊的边,问你连起这些点的总最短距离是多少. 解题分析: 因为一定要包含那条边,我们就记录下那条边 ...

  6. hdu 4463 Outlets(最小生成树)

    题意:n个点修路,要求总长度最小,但是有两个点p.q必须相连 思路:完全图,prim算法的效率取决于节点数,适用于稠密图.用prim求解. p.q间距离设为0即可,最后输出时加上p.q间的距离 pri ...

  7. hdu 4463 Outlets

    #include<bits/stdc++.h> using namespace std; double x[100+5],y[100+5]; double e[100+5][100+5]; ...

  8. hdu Constructing Roads (最小生成树)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1102 /************************************************* ...

  9. hdu 4463 第37届ACM/ICPC杭州赛区K题 最小生成树

    题意:给坐标系上的一些点,其中有两个点已经连了一条边,求最小生成树的值 将已连接的两点权值置为0,这样一定能加入最小生成树里 最后的结果加上这两点的距离即为所求 #include<cstdio& ...

随机推荐

  1. 如何将编译出来的images拷贝到windows下面刷机

    由于SPRD的刷机工具ResearchDownload运行在window环境下:这样,我们平时在开发环境下编译出来的镜像文件就不能直接用于刷机了. 这里涉及到一个双系统中文件共享的方法.由于企业信息安 ...

  2. IOS 导出ipa文件方法

    1.首先打开项目,Device选项栏选择“Generic iOS Device”.如下图所示: 2.选择屏幕上方的“product”并点击打开,选择“Archive”并点击打开,程序就会自动运行,运行 ...

  3. CodeFroces--Good Bye 2016-B--New Year and North Pole(水题-模拟)

    B. New Year and North Pole time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  4. VBS基础篇 - 循环语句(4) - For Each...Next

    VBS基础篇 - 循环语句(4) - For Each...Next   For Each...Next 循环与 For...Next 循环类似.For Each...Next 不是将语句运行指定的次 ...

  5. Chapter 1 Mr.Sherlock Holmes

    I took my degree of Doctor of Medicine in the University of London, and proceeded to Netley to go th ...

  6. URLEncode和URLDecoder作用

    一.基本原理 对于URL传递到后台,会对其中的有些字符进行编码,以下是我百度到的一些资料. 网页中的表单使用POST方法提交时,数据内容的类型是 application/x-www-form-urle ...

  7. php 项目简单分类

    项目分为:客户需求和自行研发. 商城项目:------------------------商城分类:单商家:商家就是网站所有者.如京东.凡客.          多商家:如淘宝 网站所有者不是卖家.  ...

  8. 图像相似度计算之哈希值方法OpenCV实现

    http://blog.csdn.net/fengbingchun/article/details/42153261 图像相似度计算之哈希值方法OpenCV实现 2014-12-25 21:27 29 ...

  9. Git 操作标签的一些命令

    如果标签打错了,也是可以删除: $ git tag -d v0.1Deleted tag 'v0.1' (was d96a49b) 如果要推送某个标签到远程,使用git push orign tagn ...

  10. ios 修改程序显示名称

    当你创建一个project时,会要求你输入product name & company identifier,这两个property的值should和你在apple developer mem ...