Qin Shi Huang's National Road System(次小生成树)

如何在项目中集成bpmn-process-designer 文章目录一、bpmn-process-designer是什么?二、使用步骤1.将下面地址的代码下载到本地2.替换dependencies和devDependencies3.拷贝package目录4.在main.js引入代码5.拷贝src5.拷贝App.vue代码注意事项 一、bpmn-process-designer是什么? bpmn-process-designer是一个基于 bpmn.js,Vue 2.x 和 ElementUI 开发的流程设计器(前端部分),支持监听器,扩展属性,表单等配置,可自由扩展 阅读详情

题目描述:

During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China ---- they were Qi, Chu, Yan, Han, Zhao, Wei and Qin. Ying Zheng was the king of the kingdom Qin. Through 9 years of wars, he finally conquered all six other kingdoms and became the first emperor of a unified China in 221 BC. That was Qin dynasty ---- the first imperial dynasty of China(not to be confused with the Qing Dynasty, the last dynasty of China). So Ying Zheng named himself “Qin Shi Huang” because “Shi Huang” means “the first emperor” in Chinese.

在这里插入图片描述
Qin Shi Huang undertook gigantic projects, including the first version of the Great Wall of China, the now famous city-sized mausoleum guarded by a life-sized Terracotta Army, and a massive national road system. There is a story about the road system:
There were n cities in China and Qin Shi Huang wanted them all be connected by n-1 roads, in order that he could go to every city from the capital city Xianyang.
Although Qin Shi Huang was a tyrant, he wanted the total length of all roads to be minimum,so that the road system may not cost too many people’s life. A daoshi (some kind of monk) named Xu Fu told Qin Shi Huang that he could build a road by magic and that magic road would cost no money and no labor. But Xu Fu could only build ONE magic road for Qin Shi Huang. So Qin Shi Huang had to decide where to build the magic road. Qin Shi Huang wanted the total length of all none magic roads to be as small as possible, but Xu Fu wanted the magic road to benefit as many people as possible ---- So Qin Shi Huang decided that the value of A/B (the ratio of A to B) must be the maximum, which A is the total population of the two cites connected by the magic road, and B is the total length of none magic roads.
Would you help Qin Shi Huang?
A city can be considered as a point, and a road can be considered as a line segment connecting two points.

输入:

The first line contains an integer t meaning that there are t test cases(t <= 10).
For each test case:
The first line is an integer n meaning that there are n cities(2 < n <= 1000).
Then n lines follow. Each line contains three integers X, Y and P ( 0 <= X, Y <= 1000, 0 < P < 100000). (X, Y) is the coordinate of a city and P is the population of that city.
It is guaranteed that each city has a distinct location.

输出:

For each test case, print a line indicating the above mentioned maximum ratio A/B. The result should be rounded to 2 digits after decimal point.

样例输入:

2
4
1 1 20
1 2 30
200 2 80
200 1 100
3
1 1 20
1 2 30
2 2 40

样例输出:

65.00
70.00

题目大意:

给定n个点的点权及相互间的边权,求一棵树,其中一条边的边权变为0,树的比率值为该0值边所连的两点的点权和/剩下的树边和,求这个值最大是多少。

这题要用到次小生成树的思想,即找到最小生成树,然后添加一条边构成环,再删掉环中属于最小树的最大边,用这种方法遍历所有边以找到最终长度。
在这里插入图片描述

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
int father[1005];
int n,cnt;
vector<int> huang[1005];
double d[1005][1005];
double dis[1005][1005];
int visit[1005];
struct node{
	int start,over;
	double cost;
}jiang[1000050];
struct code{
	int x,y,p;
}feng[1005];
bool cmp(node a,node b)
{
	return a.cost<b.cost;
}
void init()
{
	for(int i=0;i<1005;i++)
	{
		father[i]=i;
		huang[i].clear();
	}
}//初始化
int findd(int a)
{
	if(father[a]==a)return a;
	else return father[a]=findd(father[a]);
}
void unit(int a,int b)
{
	int x=findd(a);
	int y=findd(b);
	if(x!=y)
	{
		father[x]=y;
	}
}
double juli(int a,int b,int x,int y)
{
	return sqrt((a-x)*(a-x)+(b-y)*(b-y));
}
void dfs(int root,int where)
{
	visit[where]=1;
	for(int i=0;i<huang[where].size();i++)
	{
		int what=huang[where][i];
		if(visit[what]==0)
		{
			dis[root][what]=max(d[where][what],dis[root][where]);
			dfs(root,what);
		}
	}
}
//krustra算法
void solve()
{
	init();
	memset(d,0,sizeof(d));
	memset(dis,0,sizeof(dis));
	int num=0;
	double sum=0;
	sort(jiang,jiang+cnt,cmp);
	for(int i=0;i<cnt;i++)
	{
		if(num==n-1)break;
		else if(findd(jiang[i].start)!=findd(jiang[i].over))
		{
			unit(jiang[i].start,jiang[i].over);
			num++;
			sum+=jiang[i].cost;
			huang[jiang[i].start].push_back(jiang[i].over);
			huang[jiang[i].over].push_back(jiang[i].start);
			d[jiang[i].start][jiang[i].over]=d[jiang[i].over][jiang[i].start]=jiang[i].cost;
		}
	}
	for(int i=1;i<=n;i++)
	{
		memset(visit,0,sizeof(visit));
		dfs(i,i);
	}//找到从i~j之间的最长的那一条边的长度
	double ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			double v=sum-dis[i][j];
			v=(feng[i].p+feng[j].p)*1.0/v;
			ans=max(ans,v);
		}
	}
	printf("%.2f\n",ans);//求最大值
}
int main()
{
	int ttt;
	scanf("%d",&ttt);
	while(ttt--)
	{
		scanf("%d",&n);
		cnt=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d%d",&feng[i].x,&feng[i].y,&feng[i].p);
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=i+1;j<=n;j++)
			{
				jiang[cnt].start=i;
				jiang[cnt].over=j;
				jiang[cnt++].cost=juli(feng[i].x,feng[i].y,feng[j].x,feng[j].y);
			}
		}
		solve();
	}
	return 0;
} 
Proteus8.0仿真应用设计(九十一)基于STM32CubeMX、STM32F103C8T6 、FREERTOS、MCP41010(SPI接口)的8位数字电位器应用设计仿真 MCP41010是一款SPI接口的8位数字电位器。 阅读详情

相关推荐

音频DSP开发中的‘隐藏关卡’:那些SigmaStudio未公开的模块计算秘籍

本文深入探讨音频DSP开发中SigmaStudio未公开的模块计算秘籍,重点解析动态范围控制、均衡器参数映射和混响算法优化等核心模块计算公式。通过实际案例揭示如何利用这些非官方技巧提升音频质量与系统性能,为ADI DSP开发者提供宝贵的实战经验。

water的专栏 911

Qin Shi Huang's National Road System( 次小生成树 )

Qin Shi Huang's National Road System( 次小生成树 ) During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China ---- they were Qi, Chu, Yan, Han, Zhao, Wei and...

石旭先森的博客 267

Proteus快速入门(最详细教程)

Proteus 是一款用于嵌入式单片机仿真的软件,用于在打PCB板之前对软件程序和硬件电路的正确性进行仿真验证。1.所以Proteus一般会和Keil软件进行联合仿真,在Proteus中绘制系统的电路图,在Keil软件中编写对应的程序后生成Hex文件。2.Proteus的仿真结果仅供参考,只能在一定程度上验证系统的可能性。实际实物系统还需要进行进一步的调试。以上即为本次分享的Proteus入门教程的全部内容,希望可以能够帮助到各位道友。

ediykk的博客 15万+

[hdu-4081] Qin Shi Huang's National Road System题解

题目传送门 题意解析:题目的要求就是给你一张完全图,然后让你找出一棵生成树,并且在生成树上找出一条边,使这条边上的两个点的点权之和除以这棵生成树去掉这条边之后的边权之和最大。My opinion:我一开始看懂题意后是一脸懵逼的。什么鬼啊,这题目。于是我开始简化题目的意思,先想到了如果这棵生成树给你的后该怎么办?很显然,如果我们已经知道生成树之后,只要枚举每条边,然后找最大的答案就好了。然而我们并不

blue_tree2333的博客 386

昇腾910安装驱动出错,降低Centos7.6的内核版本

Centos7.6 启动内核修改,解决昇腾910安装驱动错误的问题。

深蓝 3300

C++中const和指针*的组合问题

今天在复习> 章节7.3的时候想到以前做的一个题,const和指针运算符*的若干种组合的合法性和意义问题,有点混淆,所以写了一个测试代码来验证一下,简单明了,一目了然。如果有什么遗漏的话欢迎指出。 首先是在Ubuntu14.04.1下用gcc 4.8.4编译运行的结果,编译器报错信息都附加在对应语句后面的注释里 /* * Note : Test for the combinations of

theColdOne的专栏 1080

图论trainning-part-1 H. Qin Shi Huang's National Road System

H. Qin Shi Huang's National Road System Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format:%I64d Java class name:Main During the Warring States Period of ancient ...

weixin_30342827的博客 255

从混乱到清晰:用QJsonObject重构你的Qt网络API数据解析层(避坑指南)

本文详细介绍了如何使用QJsonObject重构Qt网络API数据解析层,避免常见的JSON解析陷阱。通过安全解析模式、数据绑定和性能优化技巧,帮助开发者构建高效、健壮的解析逻辑,提升代码可维护性和可读性。特别适用于处理复杂嵌套的JSON响应数据场景。

weixin_29011667的博客 230

Qin Shi Huang's National Road System(HDU-4081)

Problem Description During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China ---- they were Qi, Chu, Yan, Han, Zhao, Wei and Qin. Ying Zheng was the ki...

Alex_McAvoy的博客 862

2026年数据中心运行与管理专业人才培养基地建设方案(高职、数据中心运行与管理新专业、人才培养、专业代码:510310)

摘要: 为响应国家“东数西算”战略和数字经济需求,我校拟联合行业领军企业建设数据中心运行与管理人才培养基地。项目基于国家政策引导和产业快速发展背景,针对行业10万人才缺口,对标教育部新设专业标准(510310),分三阶段实施五年规划:专业奠基(2026-2028)、内涵深化(2028-2029)、辐射引领(2030-2031)。建设内容涵盖校企协同岗位能力分析、模块化课程开发(如网络管理、自动化运维等)、实训基地搭建及“课证融通”培养模式,重点培养基础设施、网络服务、运维托管三类岗位技能人才,目标建成区域性

啊碧根果的博客 1685

Ubuntu22.04安装ros(一键搞定)

然后发现可以一键安装,话不多说,直接终端输入如下指令。回车之后系统会自动安装ros。

m0_47313541的博客 7413

hdu 4081 Qin Shi Huang's National Road System 【最小生成树的变形】

**Qin Shi Huang's National Road System** Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7448 Accepted Submission(s): 2621 Pro

逝去的时光 409

DICOM标准:DICOM医学影像中的覆盖层(Overlay)概念详解

DICOM标准:深入详解DICOM医学影像中的覆盖层(Overlay)

编程技术探索者,分享C/C++、C#、Java、数据库等开发经验,聚焦实战技巧与AI兴趣,助力编程爱好者成长。 1562

【题解】Qin Shi Huang's National Road System HDU - 4081 ⭐⭐⭐⭐ 【次小生成树】

Qin Shi Huang’s National Road System HDU - 4081 During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China ---- they were Qi, Chu, Yan, Han, Zhao, Wei and...

Suprit's blog 1481

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

hdu-4081 Qin Shi Huang's National Road System(次小生成树)

题目链接:点击打开链接 Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6405    Accepted Submission(s): 2237

TUT我好菜啊 689

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

hdu 4081 Qin Shi Huang's National Road System 次小生成树 算法

During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China ---- they were Qi, Chu, Yan, Han, Zhao, Wei and Qin. Ying Zheng was the king of the kingdom Qin. Through 9 years of wars, he finally conquered all six o

Lionel 1038

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

HDU 4081:Qin Shi Huang's National Road System(类似次小生成树问题)

Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7623    Accepted Submission(s): 2673 Problem Desc

温姑娘的博客 655

UVA 1494 - Qin Shi Huang's National Road System(次小生成树)

题目链接:点击打开链接 题意:n个城市,需要修建一些道路使得任意两个城市联通,还可以修一条魔法道路, 不花钱, 设魔法路连接的城市的人口之和为A, 所有道路总长为B, 求A/B的最大值。 思路: 次小生成树。 先做一次最小生成树, 然后用dfs搜索出最小生成树上任意两点之间最长的道路长度。  然后枚举在哪两个城市之间建魔法道路。n^2复杂度。 细节参见代码: #include #inclu

AC_Arthur的专栏 1714

hdu 4081 Qin Shi Huang's National Road System (次小生成树的变形)

题目:Qin Shi Huang's National Road System Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2049    Acc

Hadis_yuki 1145

HDU 4081 Qin Shi Huang's National Road System 次小生成树

Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10258    Accepted Submission(s): 3621   Pr...

点滴 327

hdoj 4081 Qin Shi Huang's National Road System 【次小生成树变形】

Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5200    Accepted Submission(s): 1811 Problem De

世界很大 636

HDOJ 4801 Qin Shi Huang's National Road System 次小生成树

题目地址:http://acm.hust.edu.cn/vjudge/problem/24956 次小生成树,关键是求MaxVal数组:MaxVal[u][v]保存uv点之间在mst中的边最长的边的长度 1)先求一棵MST,利用Prim算法,且在求的时候求出MaxVal数组, 更新MaxVal方法如下: prim算法中,已经加入生成树的点集合为W • 往W新增点s时,设 u 属于W,且

BRCOCOLI的博客 319

uva 1494 Qin Shi Huang's National Road System (次小生成树)

uva 1494 Qin Shi Huang's National Road System Description During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China ---- they were Qi, Chu

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 735

hdu 4081 Qin Shi Huang's National Road System(次小生成树prim)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4081 题意:有n个城市,秦始皇要修用n-1条路把它们连起来,要求从任一点出发,都可以到达其它的任意点。秦始皇希望这所有n-1条路长度之和最短。然后徐福突然有冒出来,说是他有魔法,可以不用人力、财力就变出其中任意一条路出来。 秦始皇希望徐福能把要修的n-1条路中最长的那条变出来,但是徐福希...

awow80285的博客 178

HDU 4081 Qin Shi Huang's National Road System (次小生成树)

Qin Shi Huang's National Road System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10189    Accepted Submission(s): 3605 Problem Description...

GYH0730的博客 222

HDU - 4081 Qin Shi Huang's National Road System 次小生成树

HDU - 4081 During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China ---- they were Qi, Chu, Yan, Han, Zhao, Wei and Qin. Ying Zheng was the king of the k...

qq_29904713的博客 190
上一篇: Arbitrage
下一篇: Happy 2006
大橘为重eleven
博客等级 码龄8年 35粉丝 103原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值