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

*******************************************************************************
#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. c# hasvalue属性

    // 数据类型? 表示参数的值可以为null空,此时这个参数可调用属性hasvalue来判断,此参数是否有除了null以外的值;进而进行其它的工作 //必须要加?才可用hasvalue属性 priva ...

  2. jquery $('#btn').click与$("#btn").live("click",function()有什么区别?

    live方法绑定的事件处理函数,在页面中未来添加的元素只要满足原来的选择器,仍然会导致事件触发.普通的事件绑定则没有这个效果.对于#btn这个选择器来说,如果你未来将id为btn的元素删除,然后再创建 ...

  3. Alibaba FastJson

    import com.alibaba.fastjson.JSON import com.alibaba.fastjson.JSONObject class Test { static main(arg ...

  4. tomcat - 部署Web应用

    概述 以前,安装李刚的JavaEE里面说的方法部署应用的时候,无意中成功,但是后来每次要录视频的时候,又报错,思来想去,tomcat都重启了好多次了,配置文件也试过很多次了,还是不行.无意中发现了问题 ...

  5. 【转】 自定义iOS7导航栏背景,标题和返回按钮文字颜色

    原文:http://blog.csdn.net/mad1989/article/details/41516743 UIBarButtonItem,navigationItem,backBarButto ...

  6. UITextView textViewShouldEndEditing

    最近做到UITextView, 在取消键盘事件上我以为和UITextField差不多,于是我这样写: UITextView *textView = [[UITextView alloc] initWi ...

  7. 几种常见ECG数据格式及对比

    SCP.DICOM.HL7aECG.GDF格式及对比 本文档首先给出SCP.DICOM.HL7aECG.GDF四种心电信号格式的具体数据结构,然后分析其各自的特点及适用范围. 一.SCP-ECG fo ...

  8. MESH

    本文由博主(YinaPan)原创,转载请注明出处:http://www.cnblogs.com/YinaPan/p/Unity_meshtest.html  A class that allows c ...

  9. SxsTrace工具使用方法(转)

    http://blog.sina.com.cn/s/blog_494e45fe0102dtt3.html Windows7平台上有一个强大的SxsTrace工具,可以跟踪调试应用程序运行时需要的动态库 ...

  10. underscorejs-reduceRight学习

    2.4 reduceRight 2.4.1 语法: _.reduceRight(list, iteratee, memo, [context]) 2.3.2 说明: reduceRight和reduc ...