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 ...
随机推荐
- C#学习第四天
今天主要学习了结构方面的知识,首先是定义,代码: struct<typeName> { <memberDeclarations> } struct route { public ...
- 总结Linux下查看流量工具
Linux服务器要查看带宽情况,可以使用nethogs.dstat.nload.iftop.ifstat工具. 而每个工具都有自己的特色,这里简单总结一下使用方法. 一.nethogs 查看这台设备上 ...
- UITableView中的visibleCells的用法(visibleCells帮上大忙了)
这两天遇到一个问题,UITableView中需要加入动画,而且每一行的速度不一样. 刚开始做时把所有的cell都遍历一遍加上动画,后来发现,如果数据很多时,就会出现各种各样的问题,而且没有显示在界 ...
- Swift - 22 - 循环结构
//: Playground - noun: a place where people can play import UIKit // for-in for i in -99...99 { i * ...
- Mysql 索引的基础(下)
如果需要存储大量的URL并需要根据URL进行搜索查找.如果使用B-Tree 来存储URL,存储的内容就会很大,因为URL本身都很长.正常情况下会有如下查询: SELECT id FROM url WH ...
- gdb调试带参数程序(转:笑笑小白,cnblog http://www.cnblogs.com/rosesmall/archive/2012/04/10/2440514.html)
一般来说GDB主要调试的是C/C++的程序.要调试C/C++的程序,首先在编译时,我们必须要 把调试信息加到可执行文件中.使用编译 器(cc/gcc/g++)的 -g 参数可以做到这一点.如: > ...
- 探究Android SQLite3多线程
最近做项目时在多线程读写数据库时抛出了异常,这自然是我对SQlite3有理解不到位的地方,所以事后仔细探究了一番. 关于getWriteableDataBase()和getReadableDataba ...
- 10:Hello, World!的大小
总时间限制: 1000ms 内存限制: 65536kB 描述 还记得在上一章里,我们曾经输出过的“Hello, World!”吗? 它虽然不是本章所涉及的基本数据类型的数据,但我们同样可以用siz ...
- C++学习笔记4——类的封装(2)
简介: 重载的运算符是具有特殊名字的函数:它们的名字由关键字operator和其后要定义的运算符号共同组成.其中一元运算符有一个参数,二元运算符有两个参数. 可以被重载的运算符 + - * / % ^ ...
- map 和 reduce
注意:reduce需要 from functools import reduce map的使用: >>> def func(x): ... return x*x ... >&g ...