POJ 1287-Networking
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 15174 | Accepted: 7978 |
题目链接:点击打开链接
Description
Your task is to design the network for the area, so that there is a connection (direct or indirect) between every two points (i.e., all the points are interconnected, but not necessarily by a direct cable), and that the total length of the used cable is minimal.
Input
The maximal number of points is 50. The maximal length of a given route is 100. The number of possible routes is unlimited. The nodes are identified with integers between 1 and P (inclusive). The routes between two points i and j may be given as i j or as j i.
Output
Sample Input
1 02 3 1 2 37 2 1 17 1 2 683 7 1 2 19 2 3 11 3 1 7 1 3 5 2 3 89 3 1 91 1 2 325 7 1 2 5 2 3 7 2 4 8 4 5 11 3 5 10 1 5 6 4 2 120
Sample Output
0 17 16 26
题意:
每组测试数据给你一个 n 和 m,然后 n 表示的是 n 个点,接下来会有 m 行对这 n 个点任意两点的路径进行描述,然后让你求将这 n 个点全部实现连通的最小距离,两点之间不必直接相连。
分析:
最小生成树的模板题。
#include <iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
using namespace std;#define INF 0x3f3f3f3f
int n,m;
int s[55][55];void Prim()
{int vis[55],low[55],minx,bj;int sum=0;for(int i=1;i<=n;i++){low[i]=s[1][i];}memset(vis,0,sizeof(vis));vis[1]=1;for(int i=1;i<n;i++){minx=INF;for(int j=1;j<=n;j++){if(!vis[j]&&minx>low[j]){bj=j;minx=low[j];}}vis[bj]=1;sum+=minx;for(int j=1;j<=n;j++){if(!vis[j]&&low[j]>s[bj][j])low[j]=s[bj][j];}}printf("%d\n",sum);
}int main()
{int a,b,c;while(~scanf("%d",&n)&&n){scanf("%d",&m);for(int i=0;i<=n;i++){for(int j=0;j<=n;j++){if(i==j)s[i][j]=0;elses[i][j]=INF;}}while(m--){scanf("%d %d %d",&a,&b,&c);s[a][b]=s[b][a]=min(s[a][b],c);}Prim();}return 0;
}
POJ 1287-Networking相关推荐
- 22.12.20补卡 POJ - 1287 Networking
Networking - POJ 1287 - Virtual Judge 纯模板题, 没什么好解释的 /* ⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟ ...
- POJ 1287 Networking
传送门:http://poj.org/problem?id=1287 解题思路: 简答的最小生成树 实现代码: #include <iostream> #include <cstdi ...
- poj 1287 Networking 最小生成树 Kruskal Prim
关于Kruskal和Prim在前面已经有详细的解释以及模板了 有关于需要注意的地方,以及在代码中注释出来. //Kruskal //用结构体保存起始点以及耗费,然后排序后,根据Kruskal #inc ...
- (最小生成树) Networking -- POJ -- 1287
链接: http://poj.org/problem?id=1287 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7494 ...
- B - Networking - poj 1287
有一些地方需要铺盖电缆,这些地方两点间的路可能不止一条,需要求出来至少需要多少电缆才能让所有的点都连接起来,当然,间接连接也算. / #include<iostream> #include ...
- 【POJ - 1287】 Networking (并查集 + 最小生成树)
题干: You are assigned to design network connections between certain points in a wide area. You are gi ...
- POJ 1287 Prim算法模板
原题链接:POJ1287 解析:这题我用来练习Prim算法的,算是当作一个模板来看.以下代码有几点要说明的: 我使用了优先队列,并没有使用dist[u]数组来保存当前子树到 u 的最短距离,这样省去了 ...
- 【kuangbin带你飞】专题六 最小生成树
[kuangbin带你飞]专题六 最小生成树 A.POJ - 1251 Jungle Roads (最小生成树模板) The Head Elder of the tropical island of ...
- kuangbin带你飞专题合集
题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...
- 算法学习经典例题整理
陆续会对本篇博客进行更新! 搜索:https://vjudge.net/contest/292597 区间DP:https://vjudge.net/contest/293892 树状背包:https ...
最新文章
- EF 学习 实用脚本
- C++Breadth First Search 广度优先搜索(附完整源码)
- 每天一道LeetCode-----对序列进行排序,要求nums[0] nums[1] nums[2] nums[3] ....
- 为什么要用Dubbo-远程通信背景
- Fork / Join框架vs并行流vs.ExecutorService:最终的Fork / Join基准
- objective-C CollectionView 加深(添加注册头部View)
- linux dhcp 负载均衡,dhcp双机负载均衡
- word中如何将所有字母一次修改成新罗马字体
- FPGA设计技巧总结
- 基于OpenCV文字特征提取
- 转 常用C#正则表达式收集。
- 使用Reaver破解开启了WPS功能的wifi密码(wpa/wpa2)
- 安卓加密软件_视频加密后如何播放?加密视频如何播放?
- 基于Qt编写的在线音乐播放器
- javaScript实现a页面触发b页面事件-小小笔记
- 单因素模糊评价matlab,用matlab进行模糊综合评判
- matlab模拟线圈电磁场,利用MATLAB的PDE工具箱对电场和磁场进行模拟
- 启动项目报错:null, message from server: “Host ‘XXX‘ is not allow
- Excel文件的下载
- Python挑战游戏( PythonChallenge)闯关之路Level- 3
热门文章
- com.google.guava maven依赖
- 第90届中国电子展聚焦行业新热点,拉动产业链上下游快速发展
- mysql怎么命令查看表的数据_查看MySQL数据库表的命令介绍
- 【C++】STL容器
- 转自51cto(http://smailes.blog.51cto.com/rss.php?uid=28248)
- 信号在传播中产生的不同衰落:多径效应、时延扩展和相干宽带
- w10启动无法修复此计算机,Win10启动修复无法修复你的电脑解决方法
- 计算机技术在文物修复中的应用,【3D打印技术在文物修复中的应用原稿材料】...
- Xshell下载安装教程和使用教程(超详细)
- 怎么用python画出Excel表格数据的残差图