1972 Problem E Jungle Roads

游戏开发实战:如何用旋转矩阵实现2D角色平滑转向(附Unity代码) 本文深入探讨了在Unity游戏开发中,如何运用旋转矩阵原理实现2D角色的平滑转向。文章从核心理论出发,提供了计算目标旋转、实现平滑插值(Lerp与SmoothDamp)的完整C#代码,并解决了与动画系统、物理引擎协同的常见难题,帮助开发者提升游戏操作手感与视觉流畅度。 阅读详情

问题 E: Jungle Roads

时间限制: 1 Sec  内存限制: 32 MB
提交: 21  解决: 18
 

题目描述

 

   

    The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensive to maintain. The Council of Elders must choose to stop maintaining some roads. The map above on the left shows all the roads in use now and the cost in aacms per month to maintain them. Of course there needs to be some way to get between all the villages on maintained roads, even if the route is not as short as before. The Chief Elder would like to tell the Council of Elders what would be the smallest amount they could spend in aacms per month to maintain roads that would connect all the villages. The villages are labeled A through I in the maps above. The map on the right shows the roads that could be maintained most cheaply, for 216 aacms per month. Your task is to write a program that will solve such problems.

 

输入

The input consists of one to 100 data sets, followed by a final line containing only 0. Each data set starts with a line containing only a number n, which is the number of villages, 1 < n < 27, and the villages are labeled with the first n letters of the alphabet, capitalized. Each data set is completed with n-1 lines that start with village labels in alphabetical order. There is no line for the last village. Each line for a village starts with the village label followed by a number, k, of roads from this village to villages with labels later in the alphabet. If k is greater than 0, the line continues with data for each of the k roads. The data for each road is the village label for the other end of the road followed by the monthly maintenance cost in aacms for the road. Maintenance costs will be positive integers less than 100. All data fields in the row are separated by single blanks. The road network will always allow travel between all the villages. The network will never have more than 75 roads. No village will have more than 15 roads going to other villages (before or after in the alphabet). In the sample input below, the first data set goes with the map above.

输出

The output is one integer per line for each data set: the minimum cost in aacms per month to maintain a road system that connect all the villages. Caution: A brute force solution that examines every possible set of roads will not finish within the one minute time limit.

样例输入

3
A 1 B 42
B 1 C 87
6
A 2 B 13 E 55
B 1 C 1
C 1 D 20
D 1 E 4
E 1 F 76
0

样例输出

129
114

经验总结

这题。。。。我觉得难的不是题目,难的是英文阅读理解= =|||  当然也不是很难,结合输入样例,耐心看完也是能看懂的~  其实稍微处理一下输入,中间的运算还是经典的最小生成树算法~~

正确代码

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int maxn=110;
const int INF=0x3fffffff; 
int G[maxn][maxn],d[maxn];
int n;
bool vis[maxn];
int prim()
{
	fill(d,d+maxn,INF);
	memset(vis,0,sizeof(vis));
	d[1]=0;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int min=INF,u=-1;
		for(int j=1;j<=n;++j)
		{
			if(d[j]<min&&vis[j]==false)
			{
				u=j;
				min=d[j];
			}
		}
		if(u==-1)
			return -1;
		ans+=d[u];
		vis[u]=true;
		for(int v=1;v<=n;++v)
		{
			if(vis[v]==false&&G[u][v]!=INF&&G[u][v]<d[v])
			{
				d[v]=G[u][v];
			}
		}
	}
	return ans;
}
int main()
{
	int k,w;
	char v,u;
	while(~scanf("%d",&n))
	{
		if(n==0)
			break;
		fill(G[0],G[0]+maxn*maxn,INF);
		for(int i=0;i<n-1;++i)
		{
			getchar();
			scanf("%c %d",&v,&k);
			for(int j=0;j<k;++j)
			{
				scanf(" %c %d",&u,&w);
				int v1=v-'@';
				int u1=u-'@';
				G[u1][v1]=G[v1][u1]=w;
			}
		}
		int ans=prim();
		printf("%d\n",ans);
	}
    return 0;
}

 

YOLOv11模型压缩技术全面对比:剪枝、量化、蒸馏的原理与实战 YOLOv11模型压缩技术综述 模型压缩技术是解决计算资源受限环境下部署深度学习模型的关键。本文系统介绍了YOLOv11模型压缩的三种核心技术:剪枝、量化和蒸馏。剪枝技术通过移除冗余参数实现模型轻量化,包括结构化剪枝(通道/卷积核剪枝)和非结构化剪枝;量化技术通过降低数值精度(如FP32→INT8)减少存储和计算量;蒸馏技术则利用教师模型指导学生模型训练,在保持精度的同时减小模型规模。三种技术可单独或组合使用,在工业质检、智慧安防等边缘计算场景中发挥重要作用,使YOLOv11在保持80%精度的同时减少70% 阅读详情

相关推荐

基于Arduino的智能垃圾桶

通过本次简单的Arduino智能垃圾桶小实验可以快速了解Arduino的基本用法 1、材料准备 Arduino UNO HC-SR04超声波模块 SG90舵机 杜邦线 电源 电脑 2、代码分析 电机的控制 #include<Servo.h> #define duoji D5 Servo myduoji; void setup() { myduoji.attach(duoji); //舵机连接 Serial.begin(115200); } void loop() { myduoji.w

weixin_41679960的博客 1万+

Jungle Roads丛林道路(最小生成树Prim&&Kruskal算法)

Jungle Roads丛林道路 The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expe...

m0_58245389的博客 1315

基于Unity引擎利用OpenCV和MediaPipe的面部表情和人体运动捕捉系统

增加了模型的绑定,利用Mediapipe这个强大的库可以实现识别面部表情的捕捉和人体结构运动的捕捉,基于以上的特性加入到Unity的人物模型中,实现实时的面部表情和人体运行的捕捉

BIgbossyii的博客 1万+

Jungle Roads(最小生成树、并查集)

不认识的单词: relent:发慈悲、收敛缓和 relentless:无情 elder:老大 题目描述: The Head Elder of( the tropical island)( of Lagrishan) has a problem. 热带岛的老大有个问题 A burst (of foreign aid money )was spent (on...

bijingrui的博客 315

深入解析Android Qcom Camera HAL3架构与Camx线程模块

本文深入解析了Android Qcom Camera HAL3架构与Camx线程模块的核心原理。文章以高通芯片平台为例,剖析了从按下快门到生成照片的完整Camera流程分析,重点阐述了Camx框架中线程池、消息队列及Fence同步机制如何协同工作,以实现高效、稳定的多线程并发图像处理,为相机性能优化提供理论基础。

weixin_29184075的博客 227

告别Selenium!纯Python+Requests搞定微信视频号登录Cookie(附完整代码与避坑指南)

本文详细介绍了如何利用纯Python和Requests库实现微信视频号的自动化登录,替代传统的Selenium方案。通过解析HTTP请求交互流程,提供完整的代码实现和避坑指南,显著提升爬虫效率和隐蔽性,适用于轻量化爬虫开发。

weixin_30642561的博客 317

Jungle Roads(最小生成树)

The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensive to maintain...

with_wine的博客 340

MC33PT2000控制详解一:PT2000 Dev Studio工具的使用

MC33PT2000共可控制6个高低端(如控制6个高压喷油器),1个高低端(如控制高压油泵)和DC-DC模块(如升压到65V).

m0_69929716的博客 1366

Jungle Roads (最小生成树)

The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly,...

The student way 231

Python气象数据处理实战:用PyCINRAD轻松绘制雷达PPI图像(附避坑指南)

本文详细介绍了如何使用Python库PyCINRAD处理中国CINRAD系列天气雷达的基数据,并绘制专业的PPI图像。内容涵盖从环境配置、数据读取、核心绘图到高级定制与批量处理的完整流程,并针对安装依赖、中文乱码、数据范围等常见问题提供了实用的避坑指南,帮助气象工作者高效完成雷达数据可视化。

dog123的博客 227

基于opencv人脸识别实现课堂抬头率检测系统 完整代码 可直接运行 作为毕设

基于opencv人脸识别实现课堂抬头率检测系统 完整代码 可直接运行 作为毕设

机器学习深度学习业余选手 1150

Jungle Roads(POJ-1251)

POJ - 1251 传送门 Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is.

Silence的博客 355

超声相控阵合成孔径成像FPGA设计介绍

1.仿真预览 2.理论分析 系统的基本结构如下所示: 以上是实际中完整的结构,系统中会涉及到两块板子中的时钟,这个就是设计一个时钟采样同步的问题,即所谓的时钟同步。一般这种情况,往往使用内插的方式来解决。这是由于,在实际中,超生波接收到的信号是由本身系统发送出去反射回来得到的,因此从另外一方面将,其是同步的。但是在接收的时候通过内插的方法解决其中的延迟问题。 根据论文中的介绍,整个系统分为如下几个部分: ·模拟发送信号,这个部分由MATLAB产生测试数据并量...

FPGA/MATLAB学习教程/源码/项目合作开发 2077

1972 Problem E Jungle Roads

问题 E: Jungle Roads 时间限制: 1 Sec 内存限制: 32 MB 献花: 13 解决: 11 [献花][花圈][TK题库] 题目描述 The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra...

fantasydreams的专栏 358

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

1972 Problem E Jungle Road

问题 E: Jungle Roads 时间限制:1 Sec内存限制:32 MB 提交:47解决:35 [提交][状态][讨论版][命题人:外部导入] 题目描述 The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money wa...

子衿 208

VB摄像头监控

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

Jungle Roads (最小生成树(Prim)

题目:Jungle Roads-----------POJ - 1251 vjudge提交链接 题意: ——n个村庄,村庄用大写字母A ~ Z表示。 给出n-1行数据, 每行按字母顺序排列的村庄标签开始。最后一个村庄没有排队。一个村庄的每一行都以村庄标签开始,然后是从这个村庄到后面字母表中带有标签的村庄的道路编号k。如果k大于0,则该线将继续显示k条道路的数据。每条道路的数据是道路另一端的村庄标签,然后是该道路每月维护成本。维护成本将是小于100的正整数。 ——求使n个村庄连通的最小费用。 注意:保证原始道

Helinshan的博客 296

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Jungle Roads(最小生成树 Kruskal)

Jungle Roads   The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes ro...

YOONGI 616

Jungle Roads + 最小生成树算法+ 并查集

Jungle Roads Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 4   Accepted Submission(s) : 4 Problem Description The Head Elder of the

wenlovingliu的专栏 769

poj-1251

Jungle Roads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24016   Accepted: 11265 Description The Head Elder of the tropical island of Lagrishan has

有梦的博客 473

Jungle Roads

Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads rel...

weixin_30794851的博客 164

Jungle Roads (HDU - 1301 )

Jungle Roads (HDU - 1301 ) 这道题是我以前做的最小生成树专题里的一道题,但我那时候没做。。。。。比赛出了,后悔莫及。。。。 The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads ...

菜鸡的博客 382

POJ1251最小生成树

Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensive

salmonwilliam的博客 553

题目1154:Jungle Roads

题目描述:         The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads

多看多听多总结 859

问题 E: Jungle Roads

题目描述 The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentless...

weixin_43886377的博客 298

codeup问题 E: Jungle Roads

题目描述 The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentless...

qq_41773202的博客 238

Jungle Roads (Kruskal)

The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so

码农的一亩三分地 311
上一篇: 1955 Problem D 继续畅通工程
下一篇: 1767 Problem A 算法7-12:有向无环图的拓扑排序
漫浸天空的雨色
博客等级 码龄15年 1303粉丝 523原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值