HDU1301 Jungle Roads 解题报告--prim

Context Capture10.20 安装教程(附安装包) ContextCapture 是一款由Bentley公司推出的实景建模软件,可以快速为各种类型的基础设施项目生成最具挑战性的反应现实环境的三维模型。 阅读详情

Jungle Roads

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3606    Accepted Submission(s): 2602


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

Sample Input
  
9 A 2 B 12 I 25 B 3 C 10 H 40 I 8 C 2 D 18 G 55 D 1 E 44 E 2 F 60 G 38 F 0 G 1 H 35 H 1 I 35 3 A 2 B 10 C 40 B 1 C 20 0
 

Sample Output
  
216 30
 

Source
 

Recommend
Eddy
#include<iostream>
using namespace std;
#define inf 0xffff 
int map[101][101];
int lowcost[101];
int n;
int prim()
{
	int mark[101];
	memset(mark,0,sizeof(mark));
	int sum=0;
	for(int i=0;i<n;i++)//
	{
		lowcost[i]=map[0][i];
	}
	mark[0]=1;
	for(i=1;i<n;i++)
	{
		int Min=inf;
		int pos=0;
		for(int j=0;j<n;j++)
		{
			if(Min>lowcost[j]&&mark[j]==0)
			{
				Min=lowcost[j];
                pos=j;
			}
		}
		if(Min==inf)
			break;
		mark[pos]=1;
		sum+=Min;//
		for(j=0;j<n;j++)
		{
			if(map[pos][j]<lowcost[j]&&mark[j]==0)
				lowcost[j]=map[pos][j];
		}
	}
	return sum;
}
int main()
{
	while(scanf("%d%*c",&n))
	{
		if(n==0) break;
		for(int i=0;i<n;i++)
			for(int k=0;k<n;k++)
				map[i][k]=inf;
		for(i=0;i<n-1;i++)
		{
			char a;int m;
			scanf("%c %d%*c",&a,&m);
			for(int j=0;j<m;j++)
			{
				char b;int c;
				scanf("%c %d%*c",&b,&c);
				map[a-'A'][b-'A']=map[b-'A'][a-'A']=c;
			}
		}
		cout<<prim()<<endl;;
	}
	return 0;
}

Ubuntu安装opencv4.5(自己安装过程详细) 1.下载opencv 在opencv官网下载source版,下载链接 http://opencv.org/releases.html。别下载错版本 下载过程就不多说了。 2.安装过程 2.1解压 unzip opencv-4.5.0.zip cd opencv-4.5.0 2.2安装依赖的库 sudo apt-get install cmake sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat- 阅读详情

相关推荐

通过arcmap制作的第一张流域图

需要知道,识别河流依次需要填洼,流向,流量,栅格计算器,河流链接,河网分级.通过卫星图确定河流入口,在入口处画一个点,注意不要与其他河流相交。随后是进行对河流的筛选使用con函数,筛选流量大于100的河流。我们使用镶嵌工具-->镶嵌至新栅格 将两个数据合并。填洼后如图,随后进行流向的获得.使用流向工具。首先导入准备好的数据,可见两张图片并非一体。教程参考b站up:爱画地图的boney。惊醒栅格河网矢量化,进行河流分级。输入表面栅格数据,等待后如图。本次制作的是双峰县的流域图。输入流向数据,输出后如图。

pianmian1的博客 2250

hdu 1301 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

俱往矣 688

hdu1301 prim和kruskal求最小生成树

水题 #include #include #include #include #include #include #include #include #include #include #include #include #include #define LL long long #define OJ_DEBUG 0 #define READ_FILE 0 using namespace std

她山之石,决不自弃 688

Material Studio 2024安装避坑指南:从证书配置到权限设置的完整解决方案

本文详细解析了Material Studio 2024的安装流程,从环境准备到权限优化的完整解决方案。针对证书配置、系统权限和计算服务等常见问题,提供了12个关键风险点的避坑指南,帮助科研工作者高效完成安装,提升材料模拟工作的效率。

moon9的博客 797

Ubuntu离线情况下安装gcc编译器

Ubuntu离线情况下安装gcc编译器1.系统版本2.安装说明3.异常处理 1.系统版本 (1)Ubuntu系统版本:20.04.1LTS; (2)gcc编译器版本:gcc-9.3.0(下载链接为https://download.csdn.net/download/qq_18350351/13762214); 当前可找到的gcc最新版本为gcc-10,但是笔者在安装gcc-10版本时发现一些依赖项无法安装,因此选取了gcc-9版本。如果是在联网情况下安装,直接使用apt相关的安装指令即可。 2.安装说明 安

GreenHand的博客 3942

HDU1301(最小生成树)

大意:给定一个图,求能连接所有点的最少权值和。 分析:最小生成树Prim算法。一般用于顶点较少,边较多的稠密图。 代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath&...

weixin_33770878的博客 268

利用Solidworks生成(抽取)流体通道(流道)模型

如何利用Solidworks生成流体通道模型? 在仿真计算中,尤其是流体的仿真计算中,经常涉及到流体通道的建模,而我们拿到最直接的三维结构图往往是真实的实体结构,流体通道则是实体结构的中空部分,那么在拥有实体结构的情况下,如何利用Solidworks快速建立流体通道实体结构呢? ...

XiaoAi_Liang的专栏 2万+

hdu1301 Jungle Roads (最小生成树)

Jungle Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5591    Accepted Submission(s): 4031 Problem Description The Head

苏苏爱自由 2829

【QNX Hypervisor 2.2 用户手册】2.6 处理qvm终止

你可以注册通知,以在qvm进程实例退出时得到通知。这样你就可以采取相应的措施来响应这种终止事件。

从0到1,突破自己 1116

Hermes Agent 安装部署完全指南

Hermes Agent安装部署指南提供了两种安装方式:一键脚本安装和手动分步安装。该AI助手支持多平台运行(Linux/macOS/WSL2),核心功能仅需Git作为前置依赖,其他依赖如Python、Node.js等均由安装脚本自动处理。文档详细介绍了系统要求、依赖管理、配置目录结构、环境变量设置以及10个手动安装步骤,并提供了功能模块化选项,用户可根据需求选择安装语音交互、浏览器自动化等扩展功能。安装完成后可通过hermes doctor命令验证环境,并通过交互式向导完成初始化配置。

简简单单Onlinezuozuo 2674

HDU 1301 Jungle Roads

HDU 1301 Jungle Roads Problem 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 ye

CYCKCN的博客 385

MATLAB使用贝叶斯网络bnt工具箱:使用手册详解

MATLAB使用贝叶斯bnt网络工具箱:使用手册详解

WW、forever的博客 2684

HDOJ 1301 Jungle Roads

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 源代码: //HDOJ1301 #include using namespace std; #define MAX 99999 #define LEN 30 int

90worker 2054

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Jungle Roads_hdu_1301(prim算法)

prim算法

繁华过后你还有我 827

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

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

hdu 1301 Jungle Roads(Prim算法)

Problem 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 overt

w1025758212的博客 312

Jungle Roads HDU - 1301

题意:给N给顶点接下来N-1行先输入一给字母和他能到达的字母个数NUM接下来输入的NUM组可到达的字母和花费求最小生成树 #include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include &lt...

Ray.C.L的博客 420

hdu 1301 Jungle Roads (prim)

http://acm.hdu.edu.cn/showproblem.php?pid=1301 Problem Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads betwee...

diansitao5461的博客 156

Jungle Roads hdu1301 Prim

http://acm.hdu.edu.cn/showproblem.php?pid=1301 就是一个最小生成树啦。 目测建立一个map,比建立一个road集合略容易,所以选择了Prim。还是比较基础的。 #include using namespace std; #define NROADS 78 #define INF 999 int map[NROADS][NROADS],dir[N

operator456的专栏 591

Hdu 1301 - Jungle Roads

最小生成树 - Prim算法       题意:n为村庄数目(2   例如:A 2 B 12 I 25 代表:从 A 出发一共能到达两个村庄,分别是 B 和 I ,A 到 B 的路费是12,A 到 I 的路费是25     第一次WA了,原因是 map[ ][ ] 的初始化代码写的是 memset(map, max, sizeof(map));   然后改成以下初始

Chuck的博客 874

HDU1301-Jungle Roads

http://acm.hdu.edu.cn/showproblem.php?pid=1301 #include<iostream> #include<cstdio> #include<cstring> #define INF 0xfffffff int map[28][28],f[133],n,vis[28],dis[28],min; void...

weixin_30542079的博客 117

HDU1301 Jungle Roads【Prim】

题目大意:给你一个用前N个村庄,村庄用字母表的前N个字母表示,接下来N-1行 表示第字母X与其相连的村庄数目,及其相连的村庄字母和两个村庄的距离,求最小 生成树。 思路:Prim模板题。

程序员充电站(itcharge) 1141

ACM HDOJ 1301 (Jungle Roads)

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1301 程序一 kruskal 算法 import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; public class Main { public static void main(St

陈青杨 787

hdu 1301 prime Jungle Roads

题目  http://acm.hdu.edu.cn/showproblem.php?pid=1301 我在这个题目中犯了二个错误哦,很纠结这个题目有不难  下次一定注意   第一个错误是输入有错误  搞的我一直错了, 第二个是   A 到B跟B到A点距离是相同的。 下面看具体ac代码 #include #include #include #include using namespace s

aibianchendewo的专栏 519

HDU-1301&POJ-1215 Jungle Roads

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1301 Problem Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads b...

Blank_Tt的博客 374

[HDU - 1301]Jungle Roads

建图+最小生成树 #include <cstdio> #include <cstring> #include <algorithm> #define maxn 28 #define inf 100000 using namespace std; int graph[maxn][maxn]; int vis[maxn]; int c...

dlpnyd1317的博客 98
上一篇: HDU1879 继续畅通工程 解题报告--prim
下一篇: HDU1301 Outlets 解题报告--prim
夕里子
博客等级 码龄13年 6粉丝 58原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值