HDU 4463 Outlets (prime_杭州区域赛水题)

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<cmath>
using namespace std;
double lowcost[100];
double map[111][111];
const double inf=99999999;
int vis[111];
struct node
{
	double x;
	double y;
}a[11111];

double fun(node x,node y)
{
	return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
}

int main()
{
	int n,i,j,k,u,v;
	double sum,temp,max;
	while(scanf("%d",&n)==1 && n){
	    cin>>u>>v;
		for(i=1;i<=n;i++) {
			scanf("%lf%lf",&a[i].x,&a[i].y);
			vis[i]=0;
		}
		 for(i=1;i<=n;i++) {
		 	for(j=i+1;j<=n;j++){
		 		map[i][j]=map[j][i]=fun(a[i],a[j]);
			 }
		 }
		 map[u][v]=map[v][u]=0;
		 vis[1]=1;
		 sum=fun(a[u],a[v]);
		 for(i=1;i<=n;i++) lowcost[i]=map[1][i];
		 for(i=1;i<=n;i++) {
		 	temp=inf;
		 	for(j=1;j<=n;j++) {
		 		if(!vis[j] && lowcost[j]<temp) {
		 			k=j;
		 			temp=lowcost[j];
				 }
			 }
			 if(temp==inf) break;
			 vis[k]=1;
			 sum+=temp;
			 for(j=1;j<=n;j++) {
			 	if(!vis[j] && lowcost[j]>map[k][j]) lowcost[j]=map[k][j];
			 }
		 }
		 printf("%0.2lf\n",sum);
	}
	return 0;

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-16 11:26:25

HDU 4463 Outlets (prime_杭州区域赛水题)的相关文章

HDU 4438 Hunters 区域赛水题

本文转载于 http://blog.csdn.net/major_zhang/article/details/52197538 2012天津区域赛最水之题: 题意容易读懂,然后就是分情况求出A得分的数学期望,所谓数学期望就是在该概率下的平均得分. 现在就是两种方案,Alice要根据输入给出的数据情况选出最优方案,也就是先选老虎,还是狼. 1.A先选老虎: a.B也先选老虎,则得分为Q(P*X+P*Y); //打完老虎还要打狼 b.B选狼,则两人可以直接获得猎物,则得分为(1-Q)*X 所以1方案

hdu 4463 有一条边必须加上 (2012杭州区域赛K题)

耐克店 和 苹果店必须相连 Sample Input42 30 01 00 -1 1 -10 Sample Output3.41 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <cmath> 6 # define LL long long 7 using namespace std ; 8

hdu 4463 Outlets Prim 次小生成树 简单题

Outlets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2200    Accepted Submission(s): 1028 Problem Description In China, foreign brand commodities are often much more expensive than abroad. T

2016 杭州区域赛补题

A - ArcSoft's Office Rearrangement HDU - 5933 题意:现在有n个办公区,每个办公区内有a[i]个办公人员,现在要将这些人均匀的分布在m个办公区内,每个办公区人员必须等价.现在有两个操作,1操作,可以将相邻的两个区域的人员结合在一起,2操作可以将一个办公区的人员,随意划分成两部分,两部分不一定平均,问最少需要多少次操作. 做法:贪心,从前向后枚举,不可以的情况就是不能平均的,可以预处理出来平均值,对于可以的情况,如果比平均值小,就直接加在后一个办公区内,

hdu 5122 (2014北京区域赛 K题)

把一个序列按从小到大排序 要执行多少次操作 只需要从右往左统计,并且不断更新最小值,若当前数为最小值,则将最小值更新为当前数,否则sum+1 Sample Input255 4 3 2 155 1 2 3 4 Sample OutputCase #1: 4Case #2: 1 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5

13杭州区域赛现场赛Rabbit Kingdom(树状数组+离线)

题意:给你一个长度数列,再给你m个询问(一个区间),问你在这个区间里面有多少个数与其他的数都互质. 解题思路:你看这种类型的题目都可以肯定这是 离线+树状数组(线段树).主要就是他的更新信息.这里我的处理是先把1-200000(每个数的范围)数里面所有的质因子求出来.然后从后往前遍历数组.会出现以下几种情况 1.a[k]的质因子在后面出现过而[更新标记] 和[被更新标记] 都为假 2.a[k]的质因子在后面出现过的那个位置 I   [更新标记]为 真 . 3.a[k]的质因子在后面出现过且那个位

HDU - 4813 Hard Code (长春赛区水题)

Description Some strange code is sent to Da Shan High School. It's said to be the prophet's note. The note is extremely hard to understand. However, Professor Meng is so smart that he successfully found the pattern of the code. That is, the length of

HDU 5832 A water problem(某水题)

HDU 5832 A water problem(某水题) Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Problem Description - 题目描述 Two planets named Haha and Xixi in the universe and they were created with the universe beginning. There is

hdu 1312 Red and Black(BFS水题)

Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9684    Accepted Submission(s): 6021 Problem Description There is a rectangular room, covered with square tiles. Each tile is colore