I - Agri-Net - poj 1258
貌似就是个裸的最小生成树啊
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std; const int maxn = ;
const int oo = 0xfffffff; int G[maxn][maxn]; int prim(int N)
{
int i, j, dist[maxn]={}, use[maxn]={, }; for(i=; i<=N; i++)
dist[i] = G[][i];
for(i=; i<N; i++)
{
int k = , Min = oo; for(j=; j<=N; j++)
{
if(!use[j] && Min > dist[j])
Min = dist[j], k = j;
} use[k] = true; for(j=; j<=N; j++)
if(!use[j])dist[j] = min(dist[j], G[k][j]);
} int ans = ; for(i=; i<=N; i++)
ans += dist[i]; return ans;
} int main()
{
int N; while(scanf("%d", &N) != EOF)
{
for(int i=; i<=N; i++)
for(int j=; j<=N; j++)
{
scanf("%d", &G[i][j]);
} int ans = prim(N); printf("%d\n", ans);
} return ;
}
I - Agri-Net - poj 1258的更多相关文章
- 最小生成树 10.1.5.253 1505 poj 1258 http://poj.org/problem?id=1258
#include <iostream>// poj 1258 10.1.5.253 1505 using namespace std; #define N 105 // 顶点的最大个数 ( ...
- poj 1251 poj 1258 hdu 1863 poj 1287 poj 2421 hdu 1233 最小生成树模板题
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 ...
- POJ 1258 Agri-Net|| POJ 2485 Highways MST
POJ 1258 Agri-Net http://poj.org/problem?id=1258 水题. 题目就是让你求MST,连矩阵都给你了. prim版 #include<cstdio> ...
- POJ 1258
http://poj.org/problem?id=1258 今天晚上随便找了两道题,没想到两道都是我第一次碰到的类型———最小生成树.我以前并没有见过,也不知道怎么做,然后就看书,思路很容易理解 但 ...
- poj - 1258 Agri-Net (最小生成树)
http://poj.org/problem?id=1258 FJ为了竞选市长,承诺为这个地区的所有农场联网,为了减少花费,希望所需光纤越少越好,给定每两个农场的花费,求出最小花费. 最小生成树. # ...
- POJ 1258 Agri-Net(Prim算法求解MST)
题目链接: http://poj.org/problem?id=1258 Description Farmer John has been elected mayor of his town! One ...
- (最小生成树)Agri-Net -- POJ -- 1258
链接: http://poj.org/problem?id=1258 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82831#probl ...
- Prim算法求权数和,POJ(1258)
题目链接:http://poj.org/problem?id=1258 解题报告: #include <iostream> #include <stdio.h> #includ ...
- poj 1258 Agri-Net 解题报告
题目链接:http://poj.org/problem?id=1258 题目意思:给出 n 个 farm,每个farm 之间通过一定数量的fiber 相连,问使得所有farm 直接或间接连通的 最少 ...
- POJ 1258 Agri-Net(Prim)
题目网址:http://poj.org/problem?id=1258 题目: Agri-Net Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
随机推荐
- ARM map(Program size)
1.Keil程式编译完之后,在List目录下会生成一个.map文件,里面包含各个存储块数据大小. Code:ARM 指令. RO(Read only)只读数据,如const int gu8test = ...
- linq的一些用法总结
获取列表数据. IList<Model> list = dao.getmx(Model, pageInfo);//获取数据列表 1.将列表中id一样的数据进行group by分组,并返回序 ...
- Android虚拟机GenyMotion
GenyMotion:需要VirtualBox,安装后可以选择机型,这个应该是Android for x86的一个改进版虚拟机,在原版的基础上针对不同机型用了和原机型同样的GUI,但是发现缺少了Goo ...
- c - 计算1到20的阶乘
#include <stdio.h> /* 题目:求 1+2!+3!+...+20!的和 */ unsigned long long int factorial(long n) { uns ...
- GET or POST
w3school中是这么说的: 与 POST 相比,GET 更简单也更快,并且在大部分情况下都能用. 然而,在以下情况中,请使用 POST 请求: 无法使用缓存文件(更新服务器上的文件或数据库) 向服 ...
- JavaScript 之 关键内容
词法作用域.调用对象.作用域链.闭包.构造函数.原型.类.继承 局部变量查找路径 属性查找路径
- Delphi 动态改变Rzsplitter的Orientation(方向)属性
效果图: 原先不知道,弄了半天都改不了RzSplitter.Orientation = orHorizontal / orVertical 然后去查该组件的源代码,原来Orientation不是在Rz ...
- nginx配置无效的问题
今天修改nginx的一个配置文件,却怎么都没效果,发现是启动nginx指定的配置文件不一样. #ps aux|grep nginx root 17672 0.0 0.0 45856 2 ...
- php 使用phpqrcode类生成带有logo的二维码 使logo不失真(透明)
在开发中 发现phpqrcode类在加入logo时,如果 logo 是 png 图像带有透明区域时,二维码上都无法正常完美的显示出来 解决方法便是:修改phpqrcode文件中的 QRimage类下的 ...
- thinkphp 文件下载实例 实现以及注意事项
#下载 function download() { $id=$_GET['id']; $file_name ...