题目:http://poj.org/problem?id=1258

题意:模板题 和2485差不多 就是求相连后的最小值。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
int bin[];
struct node
{
int u,v,w;
} q[];
bool cmp(node x,node y)
{
return x.w<y.w;
}
int find(int a)
{
if(a==bin[a])
return a;
else
bin[a]=find(bin[a]);
}
int main()
{
int i,j,n,num,p,m;
int x,y;
int sum;
while(~scanf("%d",&n))
{
num=; m=n*n; sum=;
for(i=; i<=n; i++)
bin[i]=i;
p=;
for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
q[p].u=i; q[p].v=j;
scanf("%d",&q[p].w);
p++;
}
sort(q,q+m,cmp);
for(i=; i<m; i++)
{
x=find(q[i].u);
y=find(q[i].v);
if(x!=y)
{
sum+=q[i].w;
num++;
bin[x]=y;
}
if(num==n-)
{
break;
}
}
cout<<sum<<endl;
}
}

poj 1259 Agri-Net(最小生成树)的更多相关文章

  1. POJ 2485 Highways【最小生成树最大权——简单模板】

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

  2. poj 1251 Jungle Roads (最小生成树)

    poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...

  3. POJ 2349 Arctic Network (最小生成树)

    Arctic Network Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  4. POJ 1751 Highways (最小生成树)

    Highways 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/G Description The island nation ...

  5. poj 3026 Borg Maze (最小生成树+bfs)

    有几个错误,调试了几个小时,样例过后 1Y. 题目:http://poj.org/problem?id=3026 题意:就是让求A们和S的最小生成树 先用bfs找每两点的距离,再建树.没剪枝 63MS ...

  6. ZOJ 1542 POJ 1861 Network 网络 最小生成树,求最长边,Kruskal算法

    题目连接:problemId=542" target="_blank">ZOJ 1542 POJ 1861 Network 网络 Network Time Limi ...

  7. ●POJ 1259 The Picnic

    题链: http://poj.org/problem?id=1259 题解: 计算几何,凸包,DP 题意:给出N($N\leq100$)个点,求出最大的凸包使得凸包里面不存在点(边上可以有).输出最大 ...

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

  9. poj 2485 Highways (最小生成树)

    链接:poj 2485 题意:输入n个城镇相互之间的距离,输出将n个城镇连通费用最小的方案中修的最长的路的长度 这个也是最小生成树的题,仅仅只是要求的不是最小价值,而是最小生成树中的最大权值.仅仅须要 ...

随机推荐

  1. python学习之html从0开始(一)

    <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content ...

  2. Delphi-仿vb里的IIF函数

    //Delphi 函数-IIF // 实例-ChkValue := IIF(TCheckBox(tsPzJz.Controls[i]).Checked, '); function IIF(lExp: ...

  3. thinkphp 使用过程中遇到的一个小函数

    1.实现导出Excel文件,并在导出的文件中显示图片 //导出 public function push(){ $goods_list=M('Dajia')->select(); $data = ...

  4. 1035 Password (20)

    #include <stdio.h> #include <string.h> struct MyStruct { ]; ]; bool changed; }; int main ...

  5. 关于分区技术的索引 index

    关于分区技术---索引 Index 一.   分区索引分类: 本地前缀分区索引(local prefixedpartitioned index) 全局分区索引(global partitionedin ...

  6. 解决未能从程序集xxx中加载类型System.ServiceModel.Activation.HttpModule的问题

    在IIS中运行网站时,出现错误: 未能从程序集“System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c ...

  7. linux 历史命令用法(转)

    许多使用过Linux一段时间的人通过一些基础操作已经能够把Linux各方面基本玩转,但是如果没有经过系统学习的话就容易缺乏一些实战技巧.这系列文章介绍一些关于bash的能够提高效率的技巧,主要是关于历 ...

  8. iOS定位坐标转换工具-b

    坐标系介绍 首先介绍一下目前的定位坐标系统1.地球坐标 :( 代号:GPS.WGS84 )--- 有W就是世界通用的也就是原始坐标体系,这是国际公认的世界标准坐标体系: 使用 WGS84 坐标系统的产 ...

  9. c#做动态(gif)中文验证码

    无意中在国外论坛发现一个gif动画类,我使用它来制作了一个动态验证码 : 一:首先新建一个类库 1:新建AnimatedGifEncoder类 using System; using System.C ...

  10. HeadFirst设计模式之模板方法模式

    一. 1.The Template Method defines the steps of an algorithm and allows subclasses to provide the impl ...