poj-1251-最小生成树】的更多相关文章

poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23507   Accepted: 11012 Description The Head Elder of the tropical island of Lagrishan has a problem. A b…
poj 1251  && hdu 1301 Sample Input 9 //n 结点数A 2 B 12 I 25B 3 C 10 H 40 I 8C 2 D 18 G 55D 1 E 44E 2 F 60 G 38F 0G 1 H 35H 1 I 353A 2 B 10 C 40B 1 C 200Sample Output 21630 prim算法 # include <iostream> # include <cstdio> # include <cstr…
D - Jungle Roads Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1251 Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extr…
题目链接:http://poj.org/problem?id=1251 字符用%s好了,方便一点. #include <stdio.h> #include <string.h> #define INF 0x3f3f3f3f ][]; ]; ]; int n; int Prim() { memset(vis,false,sizeof(vis)); ; i<=n; i++) dis[i] = INF; ; dis[] = ; ; i<=n; i++) { ; ; j<…
链接: http://poj.org/problem?id=1251 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21776   Accepted: 10086 Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra road…
双向边,基础题,最小生成树   题目 同题目     #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<string.h> #include <malloc.h> #include<stdlib.h> #include<algorithm> #include<iostream> using namespace std; #define inf 999999999 #…
Jungle Roads 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/A http://acm.hust.edu.cn/vjudge/contest/124434#problem/L Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on e…
题意: 有n个点 每个点上有一些道路 求最小生成树 解释下输入格式 A n v1 w1 v2 w2 A点上有n条边 A到v1权值是w1 A到v2权值是w2 思路: 字符串处理之后跑kruskal求最小生成树 /* *********************************************** Author :Sun Yuefeng Created Time :2016/11/9 18:26:37 File Name :tree.cpp **********************…
题意  有n个村子  输入n  然后n-1行先输入村子的序号和与该村子相连的村子数t  后面依次输入t组s和tt s为村子序号 tt为与当前村子的距离  求链接全部村子的最短路径 还是裸的最小生成树咯 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=30,M=1000; int par[N],n,m,ans; struct edge{int u…
题目: 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 exp…
题解 这是一道裸的最小生成树题,拿来练手,题目就不放了 个人理解  Prim有些类似最短路和贪心,不断找距当前点最小距离的点 Kruskal类似于并查集,不断找最小的边,如果不是一棵树的节点就合并为一颗树 AC代码: Prim算法: #include<iostream> #include<cstdio> //EOF,NULL #include<cstring> //memset #include<cstdlib> //rand,srand,system,it…
#include<iostream> #include<algorithm> using namespace std; ,tot=; const int N = 1e5; ]; struct ac{ int v,u,w; }edge[N]; bool cmp(ac a,ac b){ return a.w<b.w; } inline int find(int x){ if(x!=f[x])f[x]=find(f[x]);return f[x]; } inline int joi…
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 expensi…
题目链接:http://poj.org/problem?id=3522思路:题目要求最小生成树中最大边与最小边的最小差值,由于数据不是很大,我们可以枚举最小生成树的最小边,然后kruskal求最小生成树,直到不能生成生成树为止,然后取最小的差值即可. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define MA…
题目链接:http://poj.org/problem?id=2349 思路:由于有S个专门的通道,我们可以先求一次最小生成树,然后对于最小生成树上的边从大到小排序,前S-1条边用S-1个卫星通道连接,那么第S大条边就是我们要找的最小的D了. #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespa…
1.链接地址: http://bailian.openjudge.cn/practice/1251/ http://poj.org/problem?id=1251 2.题目: 总时间限制: 1000ms 内存限制: 65536kB 描述 热 带岛屿Lagrishan的首领现在面临一个问题:几年前,一批外援资金被用于维护村落之间的道路,但日益繁茂的丛林无情的侵蚀着村民的道路,导致道路维 修开销巨大,长老会不得不放弃部分道路的维护.上图左侧图显示的是正在使用道路的简图以及每条路每个月的维修费用(单位…
POJ 最小生成树模板 Kruskal算法 #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> #include<ctype.h> #include<stdlib.h> #include<limits.h> #include<math.h> #include<queue> #include<st…
传送门: http://poj.org/problem?id=1251 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=406 POJ RE死了,改成cin救过了..不过ZOJ原来的就能过,估计是POJ的数据多了个空格什么的. 1.prim #include<cstdio> #include<cstring> #include<iostream> using namespace std; const…
23333333333 完全是道水题.因为是偶自己读懂自己做出来的..T_T.prim的模板题水过. DESCRIPTION:John竞选的时候许诺会给村子连网.现在给你任意两个村子之间的距离.让你求任意两个村庄是连通的所需要的网线.就是求最小生成树的权值. 附代码: #include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<algorithm>#d…
DESCRIPTION:T_T 在下是读不懂题意的.但是捏.现在知道是求把所有的点(是字母的点)连起来的最小的权值.即最小生成树.因为求最小生成树是不计较源点是哪个的.所以可以把A和S看成一样的.首先需要用BFS广搜算法求出任意两点之间的最短距离.然后直接用prim或kruskal算法模板就欧克了.但是捏.貌似这道题有两大坑.NO.1 输入row 和 col 两个数之后会有多余的空格.所以需要吃掉一个字符串而不是一个字符.NO.2 虽然题目说最多有100个外星人+1个源点.但是好像有102个点.…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 AC代码: #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<queue> #include<string> #include<cmath> using namespace std; ][]; #defin…
题意:嗯……没看题……看了眼图……求个最小生成树. 解法:kruskal. 代码: #include<stdio.h> #include<iostream> #include<algorithm> #include<string> #include<string.h> #include<math.h> #include<limits.h> #include<time.h> #include<stdlib.…
想必看这道题的时候直接看数据还有那个图就能明白什么意思吧,说的已经很清楚了,每个点都有一些相连的点和权值,求出来如果连接所有点,最小的权值是多少,赤裸裸的最小生成树... ************************************************************************************ #include<iostream> #include<cstring> #include<cstdio> #include<…
题意:起点开始有超过100个人,总共不会超过100个外星人,问把所有的外星人都搜出来花的最小时间.一条路径上的时间跟人数是无关的,只跟路径长度有关. 思路:刚开始人都在起点,当派一定人数去最近的外星人后,起点就变成两个了,然后从两个起点去最近的外星人,起点就变成三个了,,,,这就是最小生成树了. include<stdio.h> #include<math.h> #include<queue> #include<stdlib.h> #include<s…
题意:求一个无向图的最小生成树,如果有多个最优解,输出"Not Unique!" 题解: 考虑kruskal碰到权值相同的边: 假设点3通过边(1,3)连入当前所维护的并查集s. 然后有一条边(下图蓝色的边)满足: 1.长度等于(1,3) 2.一端连到3,一端连入S. 那么该边可以替换掉(1,3).产生另一颗最小生成树. 关于如何判断该边一端连3,一端连入S, 用set来记录S中的点,find判断点是否在集合内.(发现kruskal可以用set写啊) #define _CRT_SEC…
2333333333 又是水题.prim模板直接水过.求最小生成树里的最大的边的权值. 附代码:// 如果我木猜错的话.是要求最小生成树的最大边值. #include<stdio.h>#include<string.h>#include<iostream>#define inf 0x1f1f1f1fusing namespace std; int n, t;int cost[520][520]; int prim(){    int low[510], vis[510]…
Description The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio transceiver a…
题目链接:http://poj.org/problem?id=2560 只想说“全都是套路”,关键建图. #include <stdio.h> #include <string.h> #include <math.h> #define INF 0x3f3f3f3f int n; ][]; ]; ]; struct Point { double x; double y; }points[]; double Prim() { memset(vis,false,sizeof(…
思路:首先使用二维数组dis[][]处理输入, 对于已经修好的路,将其对应的dis[i][j]置为零即可.最后再将    所有的dis[][]保存到边结构体中,使用Kruskal算法求得最小生成树. #include<iostream> #include<vector> #include<string> #include<cmath> #include<set> #include<algorithm> #include<cstd…
题目: 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 exp…