Agri-Net POJ - 1258 prim
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=;
#define inf 1<<29
int map[N][N],n;
int dist[N];
bool st[N];
void prim(){
memset(dist,0x3f,sizeof dist);
memset(st,,sizeof st);
int res=;
for(int i=;i<=n;i++)
{
int t=-;
for(int j=;j<=n;j++)
if(!st[j]&&(t==-||dist[t]>dist[j]))
t=j;
if(i!=)
res+=dist[t];
st[t]=true;
for(int j=;j<=n;j++)
dist[j]=min(dist[j],map[t][j]);
}
cout<<res<<endl;
} int main(){
while(cin>>n&&n){
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
cin>>map[i][j];
prim();
}
return ;
}
Agri-Net POJ - 1258 prim的更多相关文章
- Agri-Net - poj 1258 (Prim 算法)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44373 Accepted: 18127 Description F ...
- 最小生成树 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 // 顶点的最大个数 ( ...
- 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 1258 Agri-Net|| POJ 2485 Highways MST
POJ 1258 Agri-Net http://poj.org/problem?id=1258 水题. 题目就是让你求MST,连矩阵都给你了. prim版 #include<cstdio> ...
- Prim算法求权数和,POJ(1258)
题目链接:http://poj.org/problem?id=1258 解题报告: #include <iostream> #include <stdio.h> #includ ...
- POJ 1258 Agri-Net(Prim)
题目网址:http://poj.org/problem?id=1258 题目: Agri-Net Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- POJ 1258 Agri-Net(Prim算法求解MST)
题目链接: http://poj.org/problem?id=1258 Description Farmer John has been elected mayor of his town! One ...
- POJ 1258 Agri-Net(最小生成树 Prim+Kruskal)
题目链接: 传送门 Agri-Net Time Limit: 1000MS Memory Limit: 10000K Description Farmer John has been elec ...
- POJ 1258 Agri-Net(Prim)
( ̄▽ ̄)" #include<iostream> #include<cstdio> #include<cmath> #include<algori ...
随机推荐
- SSL公钥证书传递进行隐匿传输数据
title: 使用X.509公钥证书传递进行隐匿传输数据 date: 2018-02-11 17:47:50 tags: --- 使用X.509公钥证书传递进行隐匿传输数据 看到国外一篇有关于在ssl ...
- pytorch之 bulid_nn_with_2_method
import torch import torch.nn.functional as F # replace following class code with an easy sequential ...
- 杭电-------2041超级楼梯(c语言写)
/* 当未走的楼梯大于1时,可以选择走一步或者走两步,每次所做的选择相似, 符合分治法的特性,因此选择分治法,又测试用例有多组,为了避免多组 用例的重复计算,可用一个数组将已经知道的剩下的楼梯可以走的 ...
- 优雅地使用 C++ 制作表格:tabulate
作者:HelloGitHub-ChungZH 0x00 介绍 tabulate tabulate 是一个使用 C++ 17 编写的库,它可以制作表格.使用它,把表格对齐.格式化和着色,不在话下!你甚至 ...
- JS实现斐波那契数列的几种方法
斐波那契数列指的是这样一个数列:1.1.2.3.5.8.13.21.34.…… 前两项为1,从第三项起,每一项等于前两项的和,即F(1)=1,F(2)=1, F(n)=F(n-1)+F(n-2)(n& ...
- Blazui 常见问题:我更新了数据,为什么界面没刷新?
首发于:http://www.blazor.group:8000/topic/reply?tpid=9 开门见山,不介绍,不废话 建议食用本文前先食用 https://www.cnblogs.com/ ...
- HttpContext.Current.Server未将对象引用到实例
问题描述: 在一些类库中需要读取当前系统的xml文件,当时用HttpContext.Current无法找到实例化对象 解决代码如下: XmlDocument xml = new XmlDocument ...
- .NET Core MVC下的TagHelper
.NET web开发者在开发过程中,一定都踩过的坑,明明修改了js文件,可是部署到生产环境,客户反馈说:“还是报错啊”..然后一脸懵逼的去服务器上看文件,确实已经更新了.有经验的coder可能就想到了 ...
- 使用Nginx对.NetCore站点进行反向代理
前言 之前的博客我已经在Linux上部署好了.NetCore站点且通过Supervisor对站点进行了进程守护,同时也安装好了Nginx.Nginx的用处非常大,还是简单说下,它最大的功能就是方便我们 ...
- 共同战“疫”,CODING 帮助研发团队高效协同
新冠疫情下,家里蹲的日子继续延长.部分企业虽然受困于不能回公司办公,但都陆续开启了远程协作办公,远程协作领域被推上了风口.但「远程协同」看不见摸不着工作伙伴,个人的自律能力也无法保证,难免出现沟通响应 ...