poj 1259 Agri-Net(最小生成树)
题目: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(最小生成树)的更多相关文章
- POJ 2485 Highways【最小生成树最大权——简单模板】
链接: http://poj.org/problem?id=2485 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- poj 1251 Jungle Roads (最小生成树)
poj 1251 Jungle Roads (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- POJ 1751 Highways (最小生成树)
Highways 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/G Description The island nation ...
- poj 3026 Borg Maze (最小生成树+bfs)
有几个错误,调试了几个小时,样例过后 1Y. 题目:http://poj.org/problem?id=3026 题意:就是让求A们和S的最小生成树 先用bfs找每两点的距离,再建树.没剪枝 63MS ...
- ZOJ 1542 POJ 1861 Network 网络 最小生成树,求最长边,Kruskal算法
题目连接:problemId=542" target="_blank">ZOJ 1542 POJ 1861 Network 网络 Network Time Limi ...
- ●POJ 1259 The Picnic
题链: http://poj.org/problem?id=1259 题解: 计算几何,凸包,DP 题意:给出N($N\leq100$)个点,求出最大的凸包使得凸包里面不存在点(边上可以有).输出最大 ...
- 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 2485 Highways (最小生成树)
链接:poj 2485 题意:输入n个城镇相互之间的距离,输出将n个城镇连通费用最小的方案中修的最长的路的长度 这个也是最小生成树的题,仅仅只是要求的不是最小价值,而是最小生成树中的最大权值.仅仅须要 ...
随机推荐
- ARM-Linux S5PV210 UART驱动(6)----platform device的添加
开发板是飞凌OK210 arch/arm/mach-s5pv210/mach-smdkc110.c 首先是UART的寄存器默认配置信息: /* Following are default values ...
- (转)Qt Model/View 学习笔记 (五)——View 类
Qt Model/View 学习笔记 (五) View 类 概念 在model/view架构中,view从model中获得数据项然后显示给用户.数据显示的方式不必与model提供的表示方式相同,可以与 ...
- fineui框架
http://fineui.com/demo/#/demo/layout/fit.aspx 虽然比较丑陋,但功能实用 此框架比较简单, 框架的作用你懂的,重点是要有帮助文档, 进阶型的容易上手的帮助文 ...
- IE 坑爹的浏览器兼容模式
作为作为Web的前端开发人员,最悲催的莫过于要不断的,不断的去调试各种浏览器的显示效果,个人比较喜欢用火狐浏览器来做开发和调试,对于不怎么懂CSS的我来说,IE的样式调整一看就头大了.对于没有美工的团 ...
- springside springmvc 的一个SB问题
<form id="inputForm" modelAttribute="order" action="${ctx}/myorder/orde ...
- org.hibernate.LazyInitializationException
1.org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.c ...
- 利用手上的UI资源(附免费UI工具包)
http://www.uisdc.com/how-to-use-ui-kits# 大家都知道,UI工具包里有很多好看的资源:比如按钮.滑块.面包屑.播放器.表单,甚至是一个"赞!" ...
- Android 使用httpClient POST 模拟发送 multipart表单内容
使用的环境:apache-mime4j-0.6.jar,httpcore-4.3.2.jar,httpmime-4.3.3.jar try { HttpPost httpPost = new Http ...
- linux top动态查看进程信息
来源<鸟哥的linux私房菜> top:动态观察程序的变化 [root@linux ~]# top [-d] | top [-bnp] 参数: -d :后面可以接秒数,就是整个程序画面更新 ...
- codeforces #309 div1 B
题目啰里啰嗦说了一大堆(耐心读完题目就可以秒题了) 首先我们考虑当前置换的开头的循环节的开头 1.如果是1 1->1形成循环节 问题变成i-1的子问题 2.如果是2 1->2->1形 ...