博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU—4463 Outlets 最小生成树
阅读量:4540 次
发布时间:2019-06-08

本文共 2454 字,大约阅读时间需要 8 分钟。

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. 

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

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

42 30 01 00 -1 1 -10

Sample Output

3.41 题意:给你n个点,最小的价值使得所有的点连通,但是p,q一定是直连的。 这是一道比较的模板的最小生成树的题,但是要保证有一条边一定在这颗树内,我们可以使用Kruskal算法的时候,直接把ans先设置为p,q之间距离的值,然后在加边的时候把值设置为0,那么根据Kruskal算法的思想, 这个边最小肯定是最先加进来了,那么其他的就和其他的没有区别了。
#include 
#include
#include
#include
#include
using namespace std;const int maxn=105;int n,p,q;int cnt;struct Point{ int x,y;}point[maxn];struct Node{ int from,to; double value;}node[maxn*maxn];int fa[maxn];bool cmp(Node a,Node b){ return a.value

 

转载于:https://www.cnblogs.com/jkzr/p/10021561.html

你可能感兴趣的文章
Appium环境搭建——安卓模拟器(AVD)调试 1-创建模拟器失败点的总结
查看>>
System
查看>>
uiautomator特殊场景
查看>>
Monkey 启动原理分析
查看>>
go ---时间戳和Time类型的相互转化
查看>>
Tries前缀树
查看>>
TOJ4439微积分――曲线积分(数学,模拟)
查看>>
【学习中】Unity Schedule
查看>>
POJ 3169 Layout(差分约束 线性差分约束)
查看>>
模板 素数判定,求合数因子
查看>>
VS 编辑器扩展辅助工具
查看>>
Leetcode Longest Substring Without Repeating Characters (java)
查看>>
Maven 聚合与继承
查看>>
MySQL的半同步复制监控
查看>>
还是畅通工程(两种解法:prim & Kruskal)
查看>>
css初始化样例代码
查看>>
内边距、边框和外边距的关系
查看>>
模板语言--变量
查看>>
div下面多个a标签的点击事件,并且获取a的属性
查看>>
php 计算 距离
查看>>