USACO Training Section 3.1 Agri-Net

[url="http://ace.delos.com/usacoprob2?a=PvelCe17KJP&S=agrinet"]英文原题[/url] [url="http://www.wzoi.org/usaco/13%5C202.asp"]中文题译[/url]

最原始和经典的最小生成树,用了个最土最简单的办法做,编译了直接提交通过。


/*
ID: blackco3
TASK: agrinet
LANG: C++
*/
#include <iostream>
using namespace std;
#define _max_farm_ 100
int n_farm, dist[_max_farm_][_max_farm_], is_conn[_max_farm_];

int main() {
freopen("agrinet.in", "r", stdin);
freopen("agrinet.out", "w", stdout);
cin >> n_farm ;
for(int i=0; i<n_farm; i++)
for(int j=0; j<n_farm; j++)
cin >> dist[i][j] ;
int total = 0;
is_conn[0] = 1 ;
for(int n_edge=0; n_edge < n_farm-1; n_edge++) {
int min_dis = 0, sel_farm ;
for(int i=0; i<n_farm; i++)
for(int j=0; j<n_farm; j++)
if(dist[i][j] && is_conn[i] && !is_conn[j])
if(min_dis == 0 || dist[i][j] < min_dis)
min_dis = dist[i][j], sel_farm = j;
is_conn[sel_farm]=1, total += min_dis;
}
cout << total << endl ;
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值