HDU1301 Outlets 解题报告--prim

hdu4463 Outlets(必含某条边的最小生成树) 题目链接:点击打开链接 题意描述:给定一些点,在这些点之间建边使所有的点联通,要求在必须包含某条边的前提下边的权值之和最小? 解题思路:最小生成树问题prime(水题) 分析:我们将p、q两点的最短距离设为0,然后将p、q压入优先权队列中进行prime即可,记得最后加上p->q的权值即可 代码: #include #include #include #include #d 阅读详情

Outlets

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1053    Accepted Submission(s): 475


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
 

Source
 


 

#include <iostream>
#include<cmath>
#define inf 0xffff
using namespace std;
struct s
{
	int x,y;
};
double map[100][100];
int mark[100];
int n,p,q;
double prim()
{
	double sum=0;
	double lowcost[100];
	memset(lowcost,0,sizeof(lowcost));
	memset(mark,0,sizeof(mark));
	for(int i=0;i<n;i++)
	{
		if(map[p-1][i]>map[q-1][i])
			lowcost[i]=map[q-1][i];
		else
			lowcost[i]=map[p-1][i];
	}
    mark[p-1]=1;
	mark[q-1]=1;
	sum+=map[p-1][q-1];
	for(i=0;i<n-2;i++)
	{
		double Min=inf;
		int pos;
		for(int j=0;j<n;j++)
		{
			if(Min>lowcost[j]&&mark[j]==0)
			{
				Min=lowcost[j];
				pos=j;
			}
		}
		sum+=Min;
		mark[pos]=1;
		for(j=0;j<n;j++)
		{
			if(lowcost[j]>map[pos][j]&&mark[j]==0)
				lowcost[j]=map[pos][j];
		}
	}
	return sum;
}
int main()
{
    while(cin>>n)
	{
		if(n==0) break;
		else
		{
			memset(map,0,sizeof(map));
			cin>>p>>q;
			s orz[101];
			for(int i=0;i<n;i++)
			{
				int a,b;
				cin>>a>>b;
				orz[i].x=a;orz[i].y=b;
			}
			for(i=0;i<n;i++)
			{
				for(int j=i+1;j<n;j++)
				{
					map[i][j]=map[j][i]=sqrt(1.0*(orz[i].x-orz[j].x)*(orz[i].x-orz[j].x)+1.0*(orz[i].y-orz[j].y)*(orz[i].y-orz[j].y));
				}
			}
			cout<<fixed;
			cout.precision(2);
			cout<<prim()<<endl;
		}
	}
	return 0;
}


 

Loupe Browser实战指南:解锁10xGenomics单细胞数据的可视化奥秘 本文提供了Loupe Browser的实战指南,帮助用户无需编程即可探索和可视化10xGenomics单细胞数据。文章详细介绍了从数据导入、界面导航到细胞亚群鉴定、差异基因分析的核心操作流程,并分享了高级技巧与避坑指南,是快速上手这一强大可视化工具的必备参考。 阅读详情

相关推荐

测站坐标系、地心非惯性系、经纬高互转

目录 一、经纬高转直角坐标系互转 1.1 python代码 二、wgs84转cgcs2000的转换矩阵如下 虽然cgcs2000与wgs84差别很小,但是我比较较真,还是做了两个坐标系的转换。 一、经纬高转直角坐标系互转 此处可参考链接(百度文库用手机浏览器可以打开看全部的): (1)第四章地球椭球及其数学详解 (2)第四章椭球数学变换16节 (3)大地测量学基础[1](7)(控制) 转换公式如下: LBH转XYZ: a为半长轴,e为偏心率 XYZ转LBH: a为半长轴

${王小贱}的博客 2万+

HDU-4463-Outlets

HDU-4463-Outlets http://acm.hdu.edu.cn/showproblem.php?pid=4463 已知两点相连,求最小生成树,第一次参加现场赛,各种悲剧。。。这题我敲的,调试了半天才过。。。菜鸟伤不起哇。。。 #include #include #include #include #define N 100 struct node { int x; int

奋斗的菜鸟 369

【5G全网建设】Option3X和Option2模式建安市、兴城市和四水市核心网、承载网网络设计与部署

拓扑规划: Option 3X网络拓扑图规划 Option 2网络拓扑图规划 设备部署: 建安市核心网 建安市承载中心机房 建安市骨干汇聚机房 建安市3区汇聚机房 建安市C站点无线机房 兴城市核心网 兴城市承载中心机房 兴城市骨干汇聚机房 兴城市2区汇聚机房 兴城市B站点无线机房 数据配置: 建安市核心网 建安市承载中心机房 建安市骨干汇聚机房 建安市3区汇聚机房 建安市C站点无线机房 兴城市核心网 兴城市承载中心机房 兴城市骨干汇聚机房 兴城市2区汇聚机房 兴城市B站点无线机房 业务调试

weixin_67183034的博客 8883

HDU 4463 最小生成树 并查集

#include #include #include using namespace std; const int maxn=55; struct point { int x,y; }pnt[maxn]; struct edge { int s,e; double len; bool operator < (edge e) const {

MakingMaker的专栏 780

Halcon-AOI外观缺陷检测系列

Halcon-AOI外观缺陷检测系列

Jumy_S的博客 1674

open-web UI 实用指南

open-web UI 类似于chatgpt的界面,可以私有化模型本地部署,也可以用商业模型.本文只是用开源模型. 它以实现多模态AI聊天 , AI 翻译 , 语音转文本, 文本转语音, 文生图,代码助手,可谓利器。

szmars的博客 3万+

Swift outlet from the to the is invalid ,outlets cannot be connected to repeating

问题:storyBoard拖线出现问题,一般解决方法是删了重新连,或者是清理缓存等等,但是这个错误不是那样就能解决的,用静态的TableViewController时候,出现outlet from the to the is invalid ,outlets cannot be connected to repeating这种问题; 解决方案:把tableView改成静态的,文问题就解决了

抬头看山,低头看路! 1574

电阻、电容、电感的实际等效模型

1、电阻的等效模型 2、电容的寄生参数 3、电容的等效参数 4、理想铝电解电容与实际铝电解电容的区别 5、电感的等效模型  

鸟宿江边树的博客 4万+

【iOS】Illegal Configuration: The Label outlet from the ViewController to the UILabel is invalid. Outl

Illegal Configuration: The Label outlet from the ViewController to the UILabel is invalid. Outlets cannot be connected to repeating content.

柳婼 の blog 2829

YOLOv8/YOLOv11目标检测系统与多目标跟踪检测系统,使用PySide6搭建目标检测系统,支持目标检测、分割、姿势估计、旋转框,用户端系统+后台管理系统可用于大论文凑工作量或毕设必备

YOLOv8/YOLOv11目标检测系统与多目标跟踪检测系统,目标检测、分割、姿势估计、obb(旋转框),用户端系统+后台管理系统开发实战,可用于大论文凑工作量或毕设必备,全网最详细教程,系统支持 目标检测、分割、姿势估计、obb(旋转框)等模型进来检测,是一个通用的目标跟踪与目标检测系统,适配多种场景如:鱼苗检测与跟踪、行人多目标跟踪、车辆多目标跟踪、牛只行为识别与跟踪、口罩佩戴检测、安全帽佩戴检测、火灾检测等。

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 1万+

RK3566-预装APP

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档。

qq_24093081的博客 705

CollectionView stortBoard headview bug

问题点: 1.不显示问题  2.拖不出xib上的控件做属性 报错信息如下: outlets connot  be connected to repeating content 原因及解决办法: 1.因为collectionView的headerView也有复用机制,所以需要实现复用代理方法 解决如下: - (UICollectionReusableView *)coll

星宇大前端 899

YOLOv11【第二十章:模型迭代与生态闭环篇·第1节】在线增量学习——部署后新数据自动回流重训!

🏆 本文收录于专栏 《YOLOv11实战:从入门到深度优化》。本专栏围绕 YOLOv11 的改进、训练、部署与工程优化 展开,系统梳理并复现当前主流的 YOLOv11 实战案例与优化方案,内容目前已覆盖 分类、检测、分割、追踪、关键点、OBB 检测 等多个方向。

**My Coding Family** 441

hdu 4463

题目概述城市中有N家商店,编号1到N,每家的坐标为x,y,其中有两家分别是Nike和Apple,现在要为这些商店修路,其中Nike和Apple必须直接相连,其他的只要能间接连通即可,求修路总长最小值时限1000ms/2000ms输入第一行整数N,下一行两个整数Nike,Apple,代表这两家店为Nike和Apple,其后N行,每行两个整数x,y,为一家店的坐标,店按编号升序给出,输入到N=0结束限制

[CHN]liurui 411

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

hdu 4463(最小生成树变形)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4463思路:由于nike与apple必须有直接的边相连,因此可以先把这条边选进去,然后就是Kruskal求最小生成树了,由于一开始已经把点nike和点apple合并了,因此kruskal选择边的时候就不会选进去了。 1 #include&lt;iostream&gt; 2 #includ...

weixin_34250709的博客 163

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

hdu 4463 Outlets(最小生成树)

题目链接:hdu 4463 Outlets 题目大意:给定N个点,以及P,Q,问说建立N-1条边联通N个点的最短长度,要求P,Q必须建立边。 解题思路:最小生成树水题。 #include #include #include #include #include using namespace std; const int maxn = 55; struct edge {

不慌不忙、不急不躁 1031

HDU4463-Outlets

早上bc群友问的,看了他的代码一阵晕,三重for循环什么鬼! 然后自己也顺道复习一下,没有手打。。。还是拿出我的模版,看懂题意,加个简单条件,嗯,submit。 等等!wrong answer!日了狗有坑吗!拿出百度翻译,头一次遇到翻译的这么顺畅的题,完全没坑! 经检查,有一个int应该写成double,忘记改了,丢人!!! #include<stdio.h> #inc...

AC_dream 810

hdu 4463 Outlets 最小生成树

。。。

禅境花园 884

hdu 4463 Outlets

点击打开链接hdu 4463 思路:最小生成树+kruskal 分析: 1 题目要求的找到n个商店组成n-1条边,并且要求耐克和苹果商店肯定要相连,求最短长度 2 很明显的最小生成树的模板题,由于要求耐克和苹果的商店要在一起那么就要把这两个商店编号合并到同一个集合,然后在利用kruskal计算。 代码: #include&lt;iostream&gt; #include&lt;...

我是传奇 220

hdu 4463 Outlets

最小生成树

禅境花园 726

hdu4463

/* 分析:     2012亚洲杭州站K题。     水题。。。                         2012-11-08 */ #include"stdio.h" #include"string.h" #include"stdlib.h" #include"math.h" int pre[100]; struct

Ice_Crazy的专栏 1245

HDU 4463 Outlets(最小生成树)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4463 题意:要在n个商店之间修路,商店p和q必须直接通过一条马路相连,所有商店之间必须能通过马路联系,求修建马路的最小长度。 分析:其实就是简单的求最小生成树问题,不过加了一个限制条件那就是点p q必须连接在一起,可在用并查集求最小生成树之前先将pq合并到一个子集中,然后在按部就班的求即可,最

smwqd_yehua_cx的博客 509

hdu4463-Outlets

http://acm.hdu.edu.cn/showproblem.php?pid=4463 // File Name: hdu4463.cpp // Author: bo_jwolf // Created Time: Thursday, May 09, 2013 PM01:06:34 HKT #include #include #include #include #include #

bo-jwolf的专栏 1170

hdu 4463 Outlets(最小生成树,kruskal,前向星)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=4463 最小生成树的应用,但是要先把其中两个点连接起来,然后选取剩余的n-2条边。为了和纯粹的kruskal算法尽量相似,我在结构体上多下了功夫,可能看起来有点复杂。 #include #include #include #include #include #include using names

theArcticOcean 794

HDU 4463 Outlets (最小生成树kruskal算法)

Outlets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description In China, foreign brand commodities are often much more expensive than abroad. The main ...

雷银行的博客 365

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

拉斯维加斯的奥特莱斯无法满足游客 (尤其是来自中国的游客) 的购物需求。因此,将在沙漠中建造一座新的奥特莱斯,其中将包含很多商店。所有的商店之间以道路连接。设计者希望道路的总长度能够最小化。奥特莱斯的投资人雇佣了一名数据挖掘专家,该专家告诉他,Nike 商店和 Apple 商店必须由道路直接相连。请帮助他找出在此条件下的道路最短总长度。商店可被视作点,道路就是连接两个商店之间的线段。 输入 有...

博客 348

基于iOS的APP“好妈妈”开发日志九——解决tableview cell问题

基于iOS的APP“好妈妈”开发日志九——解决tableview cell问题 点击cell后消除选中效果 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: false)//点击c...

Double_s 282
上一篇: HDU1301 Jungle Roads 解题报告--prim
下一篇: 生成树的经典题--根据网上资料整理
夕里子
博客等级 码龄13年 6粉丝 58原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值