POJ 1258(最小生成树+知识)】的更多相关文章

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…
23333333333 完全是道水题.因为是偶自己读懂自己做出来的..T_T.prim的模板题水过. DESCRIPTION:John竞选的时候许诺会给村子连网.现在给你任意两个村子之间的距离.让你求任意两个村庄是连通的所需要的网线.就是求最小生成树的权值. 附代码: #include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<algorithm>#d…
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…
#include <iostream>// poj 1258 10.1.5.253 1505 using namespace std; #define N 105 // 顶点的最大个数 (多写 int a[N][N],low[N],n,ans; int min(int x,int y) { return x<y?x:y; } void prim(int u0) { int i,j,m,k; ans=0; // for (i=1;i<n;i++) low[i]=a[u0][i]; /…
POJ 1258 Agri-Net http://poj.org/problem?id=1258 水题. 题目就是让你求MST,连矩阵都给你了. prim版 #include<cstdio> const int MAXN=101; const int INF=100000+10; int map[MAXN][MAXN]; int dis[MAXN]; int n; void prim() { bool vis[MAXN]={0}; for(int i=0;i<=n;i++) dis[i]…
用kruskal算法,利用w[i]给r[i]间接排序,从而r[i]可以按照边大小保存序号,同时要判断是否在一个集合里面 #include <cstdio> #include <iostream> #include <queue> using namespace std; #define sf scanf #define pf printf #define debug printf("!\n") #define blank printf("\…
http://poj.org/problem?id=1258 FJ为了竞选市长,承诺为这个地区的所有农场联网,为了减少花费,希望所需光纤越少越好,给定每两个农场的花费,求出最小花费. 最小生成树. #include <cstdio> #include <algorithm> using namespace std; ; <<; int cost[maxn][maxn]; int mincost[maxn]; bool used[maxn]; int n; int pri…
链接: http://poj.org/problem?id=1258 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82831#problem/I Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 45751   Accepted: 18835 Description Farmer John has been elected mayor of his town!…
点击打开链接 Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33733   Accepted: 13539 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area.…
用的是prim算法. 我用vector数组,每次求最小的dis时,不需要遍历所有的点,只需要遍历之前加入到vector数组中的点(即dis[v]!=INF的点).但其实时间也差不多,和遍历所有的点的方法都是16ms... #include <iostream> #include <algorithm> #include <string.h> #include <stdio.h> #include <string> #include <que…
Agri-Net 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/H Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course.…
Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course.Farmer John ordered a high speed connection for his farm and is going to share his…
题意:给全村建光纤,求花费最小 思路:最小生成树,树相对于图来说就是没有环 m用来存图 v判断是否访问 low用来存两点间的最短距离 给low赋值  for(i=1;i<=n;i++){if(i!=pos)  low[i]=m[pos][i]  else low[i]=0;} 找最小值 即找顶点i的最小距离  for(int j=1;j<n;j++)  for(int i=1;i<=n;i++)  if(v[i]==0&&min>l[i]) min=l[i] pos…
Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64912   Accepted: 26854 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He nee…
链接:传送门! 题意:一个裸最小生成树,采用Kruskal. /************************************************************************* > File Name: poj1258.cpp > Author: WArobot > Blog: http://www.cnblogs.com/WArobot/ > Created Time: 2017年06月19日 星期一 18时20分30秒 ************…
Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 39820   Accepted: 16192 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He nee…
Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 45050   Accepted: 18479 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He nee…
题目链接: 传送门 Agri-Net Time Limit: 1000MS     Memory Limit: 10000K Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course. Farmer…
题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; #define M 110 #define inf 999999999 int mat[M][M]; int prim(int n,int sta) { int sum=0.0,dis[M]; int…
Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44827   Accepted: 18351 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He nee…
Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37131   Accepted: 14998 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He nee…
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #define MAX 102 void read(); using namespace std; int map[MAX][MAX],best[MAX],n; bool visit[MAX]; int main() { //freopen("in.txt","r",stdin…
Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 41230   Accepted: 16810 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He nee…
Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38918   Accepted: 15751 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He nee…
http://poj.org/problem?id=1258 今天晚上随便找了两道题,没想到两道都是我第一次碰到的类型———最小生成树.我以前并没有见过,也不知道怎么做,然后就看书,思路很容易理解 但我最开始确想错了,我想成每一个点只可以连接一个或者两个地方,所以那样写出来的答案根本就是错误的,也不是这个树所表达的意思 最后多次对书上的算法接合案例一步一步的进行推倒,才发现我的想法是错了,用了一个多小时 #include <stdio.h> #include <string.h>…
题目链接:http://poj.org/problem?id=1258 题目意思:给出 n 个 farm,每个farm 之间通过一定数量的fiber 相连,问使得所有farm 直接或间接连通的 最少 fiber 数是多少. 赤裸裸的最小生成树,用prim做的. 有个地方写错,wa 了 几次. #include <iostream> #include <cstdio> using namespace std; + ; const int INF = 1e9; int farm[far…
题目网址:http://poj.org/problem?id=1258 题目: Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 60004   Accepted: 24855 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet conne…
题目链接: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…
题目链接: http://poj.org/problem?id=1258 Description Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course. Farmer John ordered a high speed…