貌似就是个裸的最小生成树啊

*******************************************************************************
#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的更多相关文章

  1. 最小生成树 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 // 顶点的最大个数 ( ...

  2. 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 ...

  3. POJ 1258 Agri-Net|| POJ 2485 Highways MST

    POJ 1258 Agri-Net http://poj.org/problem?id=1258 水题. 题目就是让你求MST,连矩阵都给你了. prim版 #include<cstdio> ...

  4. POJ 1258

    http://poj.org/problem?id=1258 今天晚上随便找了两道题,没想到两道都是我第一次碰到的类型———最小生成树.我以前并没有见过,也不知道怎么做,然后就看书,思路很容易理解 但 ...

  5. poj - 1258 Agri-Net (最小生成树)

    http://poj.org/problem?id=1258 FJ为了竞选市长,承诺为这个地区的所有农场联网,为了减少花费,希望所需光纤越少越好,给定每两个农场的花费,求出最小花费. 最小生成树. # ...

  6. POJ 1258 Agri-Net(Prim算法求解MST)

    题目链接: http://poj.org/problem?id=1258 Description Farmer John has been elected mayor of his town! One ...

  7. (最小生成树)Agri-Net -- POJ -- 1258

    链接: http://poj.org/problem?id=1258 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82831#probl ...

  8. Prim算法求权数和,POJ(1258)

    题目链接:http://poj.org/problem?id=1258 解题报告: #include <iostream> #include <stdio.h> #includ ...

  9. poj 1258 Agri-Net 解题报告

    题目链接:http://poj.org/problem?id=1258 题目意思:给出 n 个 farm,每个farm 之间通过一定数量的fiber 相连,问使得所有farm 直接或间接连通的 最少 ...

  10. POJ 1258 Agri-Net(Prim)

    题目网址:http://poj.org/problem?id=1258 题目: Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

随机推荐

  1. 1_Linux_目录简介

    1. Linux中所以内容以文件形式保存,包括硬件,所以在用命令行配置文件时,该配置仅仅是临时生效.   2. Linux不靠扩展名区分类型,而是靠文件权限.之所以有扩展名是为了便于管理. .rpm二 ...

  2. HTML DOM节点

    在 DOM 树中,基本上一切都是节点.每个元素在最底层上都是 DOM 树中的节点.每个属性都是节点.每段文本都是节点.甚至注释.特殊字符(如版权符号 ©).DOCTYPE 声明(如果 HTML 或者 ...

  3. Linux Stu

    指定命令别名 alias ..='cd ..' 命令连接符 持续的执行命令,不管错误 [命令1]; [命令2]; [命令3];   前一个正确才执行下一个 [命令1] && [命令2] ...

  4. c - 计算1到20的阶乘

    #include <stdio.h> /* 题目:求 1+2!+3!+...+20!的和 */ unsigned long long int factorial(long n) { uns ...

  5. iOS9 集成指纹解锁

    添加依赖库 LocalAuthentication.framework #import <LocalAuthentication/LocalAuthentication.h> // 头文件 ...

  6. tableView Crash

    转自:http://blog.csdn.net/hamasn/article/details/8613593 Assertion failure in -[UITableView _configure ...

  7. Swift - 25 - 控制转移和二维数组

    //: Playground - noun: a place where people can play import UIKit // fallthrough // fallthrough会在当前c ...

  8. 解决Mac上Android开发时adb连接不到手机问题

    今天在Mac OS上进行Android开发的时候,打开eclipse连接不到手机MX4问题 1. 插入手机打开 Terminal,输入 system_profiler  SPUSBDataType 2 ...

  9. 使用wireshark抓本机之间的包(转)

    所转地址:http://www.chinadmd.com/file/oc6evrwtzieitexvoupppisr_1.html 在进行通信开发的过程中,我们往往会把本机既作为客户端又作为服务器端来 ...

  10. connect network is unreachable 解决办法

    详细教程见:http://blog.csdn.net/liukun321/article/details/6662950 1.虚拟机中的centos系统要连接外网,我们需要使用桥接网络 2.正常配置e ...