POJ 1258 Agri-Net (prim水题)
Agri-Net
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 1 Accepted Submission(s) : 1
Farmer John ordered a high speed
connection for his farm and is going to share his connectivity with the other
farmers. To minimize cost, he wants to lay the minimum amount of optical fiber
to connect his farm to all the other farms.
Given a list of how much fiber
it takes to connect each pair of farms, you must find the minimum amount of
fiber needed to connect them all together. Each farm must connect to some other
farm such that a packet can flow from any one farm to any other farm.
The
distance between any two farms will not exceed 100,000.
first line contains the number of farms, N (3 <= N <= 100). The following
lines contain the N x N conectivity matrix, where each element shows the
distance from on farm to another. Logically, they are N lines of N
space-separated integers. Physically, they are limited in length to 80
characters, so some lines continue onto others. Of course, the diagonal will be
0, since the distance from farm i to itself is not interesting for this
problem.
the sum of the minimum length of fiber required to connect the entire set of
farms.
0 4 9 21
4 0 8 17
9 8 0 16
21 17 16 0
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;
int e[][];
int d[];
bool v[];
int main()
{
int n, i, j;
while (cin >> n)
{
for (i = ; i <= n; i++)
{
for (j = ; j <= n; j++)
{
cin >> e[i][j];
}
}
for (i = ; i <= n; i++)
{
d[i] = e[][i];
}
memset(v, , sizeof(v));
v[] = ;
int s = ;
for (i = ; i <= n - ; i++)
{
int k = -;
int mi = ;
for (j = ; j <= n; j++)
{
if (!v[j] && d[j] <= mi)
{
mi = d[j];
k = j;
}
}
if (k == -) break;
v[k] = ;
s = s + d[k];
for (j = ; j <= n; j++)
{
if (!v[j] && d[j] > e[k][j])//这一步和dijkstra不太同,不是d[j]>d[k]+e[k][j]
{
d[j] = e[k][j];
}
}
}
cout << s << endl;
}
return ;
}
POJ 1258 Agri-Net (prim水题)的更多相关文章
- poj 3080 Blue Jeans(水题 暴搜)
题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...
- POJ 3984 - 迷宫问题 - [BFS水题]
题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- poj 1004:Financial Management(水题,求平均数)
Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 126087 Accepted: ...
- POJ 3176 Cow Bowling (水题DP)
题意:给定一个金字塔,第 i 行有 i 个数,从最上面走下来,只能相邻的层数,问你最大的和. 析:真是水题,学过DP的都会,就不说了. 代码如下: #include <cstdio> #i ...
- vijos 1069 新年趣事之红包 Prim水题
描述 xiaomengxian一进门,发现外公.外婆.叔叔.阿姨……都坐在客厅里等着他呢.经过仔细观察,xiaomengxian发现他们所有人正好组成了一个凸多边形.最重要的是,他们每个人手里都拿着一 ...
- poj 1658 Eva's Problem(水题)
一.Description Eva的家庭作业里有很多数列填空练习.填空练习的要求是:已知数列的前四项,填出第五项.因为已经知道这些数列只可能是等差或等比数列,她决定写一个程序来完成这些练习. Inpu ...
- POJ 1258:Agri-Net Prim最小生成树模板题
Agri-Net Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 45050 Accepted: 18479 Descri ...
- POJ 1258 Agri-Net (最小生成树+Prim)
Agri-Net Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 39820 Accepted: 16192 Descri ...
随机推荐
- 在多节点上运行分布式Intel Caffe
一般有2种并行模式:数据并行(Data parallelism)和模型并行(model parallelism). 在模型并行化( model parallelism )方法里,分布式系统中的不同机器 ...
- 基于Codis的Redis集群部署
Codis是基于代理的高性能Redis集群方案,使用Go语言进行开发,现在在在豌豆荚及其它公司内已经广泛使用,当然也包括我们公司. Codis与常见的Redis集群方案对比. 在搭建的时候,个人觉得R ...
- java中interrupt、join、sleep、notify、notifyAll、wait详解
首先介绍一下中断概念:举个例子容易理解一点 例子:假如你正在给朋友写信,电话铃响了.这时,你放下手中的笔,去接电话.通话完毕,再继续写信.这个例子就表现了中断及其处理过程:电话铃声使你暂时中止当前的工 ...
- Linux 常用环境搭建
已有环境 python 2.6.6 jdk 1.7 —tomcat— —jenkins— —jq— —Python 2.7— —pip— —PIL— —Android SDK— —yum or apt ...
- activemq、rabbitmq、kafka原理和比较
一.activemq 虽然是java写的消息队列,但是提供Java, C, C++, C#, Ruby, Perl, Python, PHP各种客户端,所以语言上是没什么问题的.配置和使用,基本上是j ...
- HTMLElement.hidden; CSS Attr Selectors的用处; DOM的className方法; ::before和::after伪元素
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/hidden https://codepen.io/pen/ <elem ...
- 分享6款优秀的 AR/VR 开源库
今天,为大家推荐几款优秀的 AR/VR 开源库,希望能对大家有所帮助~ 1.AR.js AR.js 是一款应用于 Web 的高效增强现实(AR)库,基于 three.js + jsartoolkit5 ...
- Android之扫描二维码和根据输入信息生成名片二维码
开发中常常遇到二维码扫码操作,前段时间做项目要实现该功能,于是网上查找资料实现了,现在把他做出来给各位分享一下,主要包含了二维码扫描和生成二维码名片. 先来看看效果图: 生成的二维码,打开微信扫一 ...
- UVA-1660 Cable TV Network (最小割)
题目大意:给一张n个点.m条边的无向图,求最小点割集的基数. 题目分析:求无向图最小点割集的基数可以变成求最小割.考虑单源s单汇t的无向图,如果要求一个最小点集,使得去掉这个点集后图不再连通(连通分量 ...
- 修改oracle表空间数值
alter database datafile 'D:\oracle\dbfile\DATA.DBF' autoextend on next 100m maxsize 2000M;