POJ 1258 Agri-Net(Prim)】的更多相关文章

( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<string> #include<cstdlib> #include<vector> using namespace std; typedef long long ll; const int…
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…
题意:n个农场,求把所有农场连接起来所需要最短的距离. 思路:prim算法 课本代码: //prim算法 #include<iostream> #include<stdio.h> #include<cstring> using namespace std; int n; int tot; int v[150][150]; int dist[150];//存 节点到树 的最小距离 bool use[150];//标记节点是否存在 int main(){ while(sca…
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 : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total Submission(s) : 1   Accepted Submission(s) : 1 Problem Description Farmer John has been elected mayor of his town! One of his campaign promises was to bri…
#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 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…
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]…
题目链接:http://poj.org/problem?id=1258 解题报告: #include <iostream> #include <stdio.h> #include <string.h> #include <memory.h> using namespace std; #define N 10005 #define inf 100010 int a[N][N],ans; bool vis[N]; int dis[N],n; bool Prim(…
题目网址: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=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…
题目链接: 传送门 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…
题意:FJ想连接光纤在各个农场以便网络普及,现给出一些连接关系(给出邻接矩阵),从中选出部分边,使得整个图连通.求边的最小总花费. 思路:裸的最小生成树,本题为稠密图,Prim算法求最小生成树更优,复杂度O(n^2) prim: #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; int mat[110][110]…
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…
  Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44373   Accepted: 18127 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…
Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44487   Accepted: 18173 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…
很裸地求最小生成树的题目.题意就不多说了,最重要的就是记录一下学会了prim算法. 初学prim,给我的第一感觉就是和dijkstra好像啊,感觉两者的区别还是有的: 1:prim是求最小生成树的算法. dijkstra是求最短路的算法. 2:prim中dis保存的是未加入集合的点,加入集合需要的代价,而已经加入集合中的点加入花费代价是其他变量保存的. dijkstra中dis保存的是从起点到当前点所花费的最小代价. #include <cstdio> #include <cstring…
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…
#include<iostream> #include<cstdio> #include<cstring> using namespace std; ; #define inf 1<<29 int map[N][N],n; int dist[N]; bool st[N]; void prim(){ memset(dist,0x3f,sizeof dist); memset(st,,sizeof st); ; ;i<=n;i++) { ; ;j<=…
http://poj.org/problem?id=1258 今天晚上随便找了两道题,没想到两道都是我第一次碰到的类型———最小生成树.我以前并没有见过,也不知道怎么做,然后就看书,思路很容易理解 但我最开始确想错了,我想成每一个点只可以连接一个或者两个地方,所以那样写出来的答案根本就是错误的,也不是这个树所表达的意思 最后多次对书上的算法接合案例一步一步的进行推倒,才发现我的想法是错了,用了一个多小时 #include <stdio.h> #include <string.h>…
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!…
题目链接: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=3026 题意:任意两个字母可以连线,求把所有字母串联起来和最小. 很明显这就是一个最小生成树,不过这个题有毒.他的输入有问题.在输入m和N后面,可能有一大串的空格.就因为这个,我RE都有点懵了,要不是discuss里面有人说输入有问题,我都没注意到这个,原本只用了一个getchar吃掉最后的换行符.没想到之后还有空格.有点小坑. 思路:这个题目如果他给你一个图,那就是最裸的prim了.不过这个题的难点也就是在他给的图你不能用Prim,你只能通…
题目链接:http://poj.org/problem?id=1789 还是套路. #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<=n;…
题目链接: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(…
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=2031 Description You are a member of the space station engineering team, and are assigned a task in the construction process of the station. You are expected to write a computer program to complete the task.  The space stati…
23333333333 完全是道水题.因为是偶自己读懂自己做出来的..T_T.prim的模板题水过. DESCRIPTION:John竞选的时候许诺会给村子连网.现在给你任意两个村子之间的距离.让你求任意两个村庄是连通的所需要的网线.就是求最小生成树的权值. 附代码: #include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<algorithm>#d…