POJ 2485】的更多相关文章

链接:poj 2485 题意:输入n个城镇相互之间的距离,输出将n个城镇连通费用最小的方案中修的最长的路的长度 这个也是最小生成树的题,仅仅只是要求的不是最小价值,而是最小生成树中的最大权值.仅仅须要加个推断 比較最小生成树每条边的大小即可 kruskal算法 #include<cstdio> #include<algorithm> using namespace std; int f[510],n,m; struct stu { int a,b,c; }t[20100]; int…
[POJ 2485] Highways 最小生成树模板 Prim #include using namespace std; int mp[501][501]; int dis[501]; bool vis[501]; int n; int Prim() { int i,j,w,p,mm = 0; memset(dis,-1,sizeof(dis)); memset(vis,0,sizeof(vis)); dis[1] = 0; for(i = 0; i < n; ++i) { w = INF;…
题目连接 http://poj.org/problem?id=2485 Highways Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They…
链接: http://poj.org/problem?id=2485 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#problem/H Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18668   Accepted: 8648 Description The island nation of Flatopia is perfect…
题目链接:http://poj.org/problem?id=2485 解题报告: 这里有一点要注意的是,第一个点时,dis数组还没有初始化,还全部为inf.第一次来到更新权时,才把邻接矩阵的数据存到dis中. #include <iostream> #include <stdio.h> #include <string.h> #include <memory.h> #include <algorithm> using namespace std…
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]…
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning to build some highways so that i…
/*kruskal算法*/ #include <iostream> //#include <fstream> #include <algorithm> using namespace std; /*708K 922MS*/ typedef struct _edge { int x,y; int w; }edge; int n; int num; //fstream fin; void kruskal(edge *e,int len); int cmp(const voi…
题目链接:Highways 没看题,看了输入输出.就有种似曾相识的感觉,果然和HDU1102 题相似度99%,可是也遇到一坑 cin输入居然TLE,cin的缓存不至于这么狠吧,题目非常水.矩阵已经告诉你了.就敲个模板就是了,5分钟.1A 题意就是打印,最小生成树的最大边权.改了改输入,水过 这个题完了.我的个人POJ计划进度以完毕 20/200,这当中主要是图论的题.等下周把POJ计划图论的题目打完,就回头打模拟!我就不信还能比图论难 #include <iostream> #include…
题目 Prim算法:任选一个点,加入集合,找出和它最近的点,加入集合,然后用加入集合的点去更新其它点的最近距离......这题求最小生成树最大的边,于是每次更新一下最大边. #include <cstdio> #define max(x, y) ((x) > (y) ? (x) : (y)) #define N 505 int t, n, g[N][N], lowcost[N], used[N], ans; void prim(){ for(int i = 1; i <= n; i…
点击打开链接 Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19004   Accepted: 8815 Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia.…
题目 //听说听木看懂之后,数据很水,我看看能不能水过 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; #define M 510 #define inf 999999999 int mat[M][M]; int prim(int n,int sta) {…
Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21628   Accepted: 9970 Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Fla…
对于终于生成的最小生成树中最长边所连接的两点来说 不存在更短的边使得该两点以不论什么方式联通 对于本题来说 最小生成树中的最长边的边长就是使整个图联通的最长边的边长 由此可知仅仅要对给出城市所抽象出的图做一次最小生成树 去树上的最长边就可以 #include<bits/stdc++.h> using namespace std; int T,n,a,dist[1020],m[1020][1020]; void prim() { bool p[1020]; for(int i=2;i<=n…
( ̄▽ ̄)" //求最短总路径中的最大边长,Prim还需要一个Max变量 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<vector> #include<queue> using namespace std; ; const int INF=10e8; int k,minn; int c[MAXN][MAX…
Sample Input 1 //T 3 //n0 990 692 //邻接矩阵990 0 179692 179 0Sample Output 692 prim # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # define LL long long using namespace std ;…
#include<iostream> #define MAXN 505 #define inf 1000000000 using namespace std; typedef int elem_t; int _m[MAXN][MAXN]; int pre[MAXN]; elem_t prim(int n,elem_t mat[][MAXN],int* pre); int main() { //freopen("acm.acm","r",stdin); i…
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 islandnation of Flatopia is perfectly flat. Unfortunately, Flatopia has no publichighways. So the traffic is difficult in Flatopia. The Flatopian government isaware of this problem. They're planning to build some highways so that…
Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23033   Accepted: 10612 Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Fl…
  Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24383   Accepted: 11243 Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian…
                                                                                                                Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23426   Accepted: 10829 Description The island nation of Flatopia is…
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning to build some highways so that i…
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning to build some highways so that i…
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning to build some highways so that i…
A国没有高速公路,因此A国的交通很困难.政府意识到了这个问题并且计划建造一些高速公路,以至于可以在不离开高速公路的情况下在任意两座城镇之间行驶. A国的城镇编号为1到N, 每条高速公路连接这两个城镇,所有高速公路都可以在两个方向上使用.高速公路可以自由的相互交叉. A国政府希望尽量减少最长高速公路的建设时间(使建设的最长的高速公路最短),但是他们要保证每个城镇都可以通过高速公路到达任意一座城镇. Input 第一个输入的数字T,代表着T组样例. 接下来输入一个N, 代表一共有N个城镇. 然后读入…
OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递推. 构造法.(POJ 3295) 模拟法.(POJ 1068,POJ 2632,POJ 1573,POJ 2993,POJ 2996) 二…
著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 3094) 初期: 一.基本算法: 枚举. (POJ 1753,POJ 2965) 贪心(POJ 1328,POJ 2109,POJ 2586) 递归和分治法. 递…
普里姆算法(Prim算法),图论中的一种算法,可在加权连通图里搜索最小生成树.意即由此算法搜索到的边子集所构成的树中,不但包括了连通图里的所有顶点,且其所有边的权值之和亦为最小.该算法于1930年由捷克数学家沃伊捷赫·亚尔尼克发现:并在1957年由美国计算机科学家罗伯特·普里姆独立发现:1959年,艾兹格·迪科斯彻再次发现了该算法.因此,在某些场合,普里姆算法又被称为DJP算法.亚尔尼克算法或普里姆-亚尔尼克算法 算法过程图解:遍历点,用贪心法选择与集合内的点相连的点的最小值: 模板: #inc…
一.知识目录 字符串处理 ................................................................. 3 1.KMP 算法 ............................................................ 3 2.扩展 KMP ............................................................ 6 3.Manacher 最长回文子串 .......…