最小生成树 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 ...
随机推荐
- NetAdvantage webdatagrid 控件的一些属性
属性: 1 behaviors 行为下的属性集合 Row Selectors 主要用于设置行选择样式与形为的集合 Enable 属性表示是否启用 Row Selectors下的属性设置 RowNumB ...
- 用Ueditor存入数据库带HTML标签的文本,从数据库取出来后,anjular用ng-bind-html处理带HTML标签的文本
ng.module('index-filters', []) .filter('trustHtml', function ($sce) { return function (input) { retu ...
- CSRF 攻击的应对之道
转载自imb文库 CSRF(Cross Site Request Forgery, 跨站域请求伪造)是一种网络的攻击方式,该攻击可以在受害者毫不知情的情况下以受害者名义伪造请求发送给受攻击站点,从而在 ...
- Notification和KVO有什么不同
Notification是推送通知,我们可以建立一个通知中心,存放创建多个通知,在不同的地方在需要的时候push调用和KVO不同的是,KVO是键值观察,只能观察一个值,这就是区别
- SGU 123.The sum
#include <iostream> using namespace std; int f[50]={0,1,1}; int main(){ int n,s=0; cin>> ...
- 如何使一个input文本框随其中内容而变化长度。
第一:<input type="text" onkeydown="this.onkeyup();" onkeyup="this.size=(th ...
- css清除浮动方法大全
清除浮动这个问题,做前端的应该再熟悉不过了,也是每一个web前台设计师 必须掌握的机能. 为什么浮动这么难? 因为浮动会使当前标签产生向上浮的效果,同时会影响到前后标签.父级标签的位置及 width ...
- PHPCMS收集标签使用
调用子栏目(在栏目首页模板需要用到) {pc:content action="category" catid="$catid" num="25&quo ...
- linux下gdal的python包的安装
由于python包是从C++包编译出来的,所以需要先下载源码进行编译安装.1. gdal下载http://download.osgeo.org/gdal/CURRENT/sudo ./configur ...
- ural1057Amount of Degrees
Description Create a code to determine the amount of integers, lying in the set [ X; Y] and being a ...