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 ...
随机推荐
- Nginx反向代理,负载均衡配置
主配置文件:nginx.conf # For more information on configuration, see: # * Official English Documentation: h ...
- jQueryUI 日期控件
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Inse ...
- 下拉框上移、下移、添加、移除demo
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> <sc ...
- 【转】数据库分页Java实现
[转]数据库分页Java实现 MySQL分页 主要是MySQL数据库内置LIMIT函数 注意添加mysql的JAR包mysql-connector-java-5.1.13-bin.jar 在中小数据量 ...
- LINQ to SQL 基础
取得数据库Gateway 要操作数据库,我们首先要获得一个DataContext对象,这个对象相当于一个数据 库的Gateway,所有的操作都是通过它进行的.这个对象的名字是“Linq to SQL ...
- eclipse设置和优化
1.eclipse下的编码设置: eclipse 中使用模板新建 JSP,xhtml等 文件时,默认的编码为:ISO-8859-1. ISO-8859-1 编码对于中文的显示是不支持的,如果要支持简体 ...
- directshow filter 调试步骤
1,编写filter 2,在debug模式下build 3,注册filter:控制台cd到工程的debug目录下,即欲注册的filter(.ax文件)目录,xx:>regsvr32 contra ...
- 如何使一个你没有源代码的DLL文件变为强命名的DLL
转载: 有时候你会需要一个DLL是强命名的,比如你想把这个文件放到GAC里面.如果这是一个第三方的DLL,你没有源代码,这会是一件比较麻烦的事情.有一个方法可以解决这个问题. 在VS.NET的命名行窗 ...
- Delphi-CompareStr 函数
函数名称 CompareStr 所在单元 System.SysUtils 函数原型 function CompareStr(const S1, S2: string): Integer; 函数功能 比 ...
- Day5 双层装饰器、字符串格式化、生成器、迭代器、递归
双层装饰器实现用户登录和权限认证 #!/usr/bin/env python# -*- coding: utf-8 -*-# Author: WangHuafeng USER_INFO = {} de ...