最小生成树 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 // 顶点的最大个数 (多写
int a[N][N],low[N],n,ans;
int min(int x,int y)
{ return x<y?x:y; } void prim(int u0)
{
int i,j,m,k;
ans=0; //
for (i=1;i<n;i++)
low[i]=a[u0][i]; //
low[u0]=-1;
for (i=1;i<n;i++) //循环n-1次 依次加入n-1个顶点
{
m=1<<20;
for (j=0;j<n;j++) //找一个最小的的边
if (low[j]!=-1&&low[j]<m)
{ m=low[j]; k=j; }
ans+=m; //
low[k]=-1;
for (j=0;j<n;j++) //
if (low[j]!=-1)
low[j]=min(low[j],a[k][j]);
}
} int main()
{
int i,j;
while(cin>>n&&n>=3)
{
for (i=0;i<n;i++) //邻接矩阵
for (j=0;j<n;j++)
cin>>a[i][j];
prim(0); // 从0开始
cout<<ans<<endl;
}
return 0;
}
最小生成树 10.1.5.253 1505 poj 1258 http://poj.org/problem?id=1258的更多相关文章
- POJ 1258 Agri-Net|| POJ 2485 Highways MST
POJ 1258 Agri-Net http://poj.org/problem?id=1258 水题. 题目就是让你求MST,连矩阵都给你了. prim版 #include<cstdio> ...
- BFS 10.1.5.253 1502
http://10.1.5.253/acmhome/problemdetail.do?&method=showdetail&id=1502 //1502 #include <st ...
- poj 1651 http://poj.org/problem?id=1651
http://poj.org/problem?id=1651Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K To ...
- poj 1679 http://poj.org/problem?id=1679
http://poj.org/problem?id=1679 The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- OpenJudge/Poj 1207 The 3n + 1 problem
1.链接地址: http://bailian.openjudge.cn/practice/1207/ http://poj.org/problem?id=1207 2.题目: 总时间限制: 1000m ...
- POJ 1201 Intervals || POJ 1716 Integer Intervals 差分约束
POJ 1201 http://poj.org/problem?id=1201 题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai, ...
- poj-3056 http://poj.org/problem?id=3056
http://poj.org/problem?id=3056 The Bavarian Beer Party Time Limit: 6000MS Memory Limit: 65536K Tot ...
- POJ3278http://poj.org/problem?id=3278
http://poj.org/problem?id=3278 题目大意: m,n两个数m可+1, -1, *2变成n,需要经过几步 #include<stdio.h> #include&l ...
- POJ 3320 Jessica‘s Reading Problem(哈希、尺取法)
http://poj.org/problem?id=3320 题意:给出一串数字,要求包含所有数字的最短长度. 思路: 哈希一直不是很会用,这道题也是参考了别人的代码,想了很久. #include&l ...
随机推荐
- Http,Https (SSL)的Url绝对路径,相对路径解决方案Security Switch 4.2 英文帮助文档 分类: ASP.NET 2014-10-28 10:50 147人阅读 评论(1) 收藏
Security Switch 4.2 =================== Security Switch enables various ASP.NET applications to auto ...
- copy file using FileReader/Writer.
The code below demonstates copying file using 'FileReader' and 'FileWriter'. class CopyV2 extends Ti ...
- log4Net配置详解
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSe ...
- 制作SSL证书
上一节介绍了OpenSSL的目录结构,本节介绍一下SSL证书的制作. OpenSSL安装后建议把其中的bin目录添加到系统环境变量中,方便以后操作. 建立一个新的目录SSL专门用来制作证书. 建立证书 ...
- Deep Learning 学习随记(四)自学习和非监督特征学习
接着看讲义,接下来这章应该是Self-Taught Learning and Unsupervised Feature Learning. 含义: 从字面上不难理解其意思.这里的self-taught ...
- JS特殊符号
反斜杠用来在文本字符串中插入省略号.换行符.引号和其他特殊字符. 代码 输出 \' 单引号 \" 双引号 \& 和号 \\ 反斜杠 \n 换行符 \r 回车符 \t 制表符 \b 退 ...
- (一)Nodejs - 框架类库 - Nodejs异步流程控制Async
简介 Async是一个流程控制工具包,提供了直接而强大的异步功能 应用场景 业务流程逻辑复杂,适应异步编程,减少回调的嵌套 安装 npm insatll async 函数介绍 Collections ...
- web版扫雷小游戏(一)
作为一名程序猿,平时的爱好也不多,说起游戏,我不太喜欢大型的网游,因为太耗时间,偶尔玩玩经典的单机小游戏,比如windows下自带的游戏扫雷(秀一下,高级下最高纪录110s). 现阶段正在致力于web ...
- 小心DriveInfo类IsReady属性的较大延迟问题
当某些驱动器调用IsReady属性来判断是否准备好时,会有性能问题,会非常慢,特别是网络驱动器断开的时候,这个属性会有30秒左右的延迟,这对程序执行是非常大的开销,请慎重调用
- 更换Python默认软件镜像源
限于一些众所周知的原因,在我们pip安装软件的时候出现类似报错: data = self.read(amt=amt, decode_content=decode_content) File " ...