minimal spanning tree的经典题

 /*
 ID: yingzho1
 LANG: C++
 TASK: agrinet
 */
 #include <iostream>
 #include <fstream>
 #include <string>
 #include <map>
 #include <vector>
 #include <set>
 #include <algorithm>
 #include <stdio.h>
 #include <queue>
 #include <cstring>
 #include <cmath>
 #include <list>

 using namespace std;

 ifstream fin("agrinet.in");
 ofstream fout("agrinet.out");

 ;

 int N;
 ][];
 ];
 ;

 void prim() {
     ; i < N; i++) dis[i] = inf;
     ] = {false};
     ;
     int min_w;
     int flag;
     visit[s] = true;

     ; i < N; i++) {
         min_w = inf;
         ; j < N; j++) {
             if (!visit[j] && dis[j] > dist[s][j]) dis[j] = dist[s][j];
             if (!visit[j] && min_w > dis[j]) {
                 min_w = dis[j];
                 //cout << min_w << endl;
                 flag = j;
             }
         }
         s = flag;
         visit[s] = true;
         total_dist += min_w;
     }
 }

 int main()
 {
     fin >> N;
     ; i < N; i++) {
         ; j < N; j++) {
             fin >> dist[i][j];
         }
     }
     prim();
     fout << total_dist << endl;

     ;
 }

USACO Section 3.1: Agri-Net的更多相关文章

  1. USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)

    usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...

  2. USACO Section 3.3: Riding the Fences

    典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...

  3. USACO Section 3.3 Camlot(BFS)

    BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...

  4. [IOI1996] USACO Section 5.3 Network of Schools(强连通分量)

    nocow上的题解很好. http://www.nocow.cn/index.php/USACO/schlnet 如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断. --------- ...

  5. USACO Section 5.3 Big Barn(dp)

    USACO前面好像有类似的题目..dp(i,j)=min(dp(i+1,j),dp(i+1,j+1),dp(i,j+1))+1  (坐标(i,j)处无tree;有tree自然dp(i,j)=0) .d ...

  6. USACO Section 1.3 Prime Cryptarithm 解题报告

    题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...

  7. USACO Section 1.1 Your Ride Is Here 解题报告

    题目 问题描述 将字符串转变为数字,字母A对应的值为1,依次对应,字母Z对应的值为26.现在有一个字符串,将其中的每个字符转变为数字之后进行累乘,最终的结果对47求余数. 题目给你两个字符串,其中的字 ...

  8. USACO Section 1.1-1 Your Ride Is Here

    USACO 1.1-1 Your Ride Is Here 你的飞碟在这儿 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...

  9. USACO section 1.1 C++题解

    USACO section1.1:DONE 2017.03.03 TEXT Submitting Solutions DONE 2017.03.04 PROB Your Ride Is Here [A ...

  10. USACO Section 1.1PROB Your Ride Is Here

    题目传送门 不能提交哦   http://www.nocow.cn/index.php/Translate:USACO/ride /* ID: jusonal1 PROG: ride LANG: C+ ...

随机推荐

  1. Asp.net开启分布式事务管理

    1.确保服务器分布式管理服务 Distributed Transcation Coordinator 有开启 2.使用分布式事务代码的项目中添加System.Transactions程序集的引用 3. ...

  2. Careercup - Google面试题 - 5162732873580544

    2014-05-08 08:26 题目链接 原题: Given a preorder traversal, create a binary search tree in optimized time ...

  3. 【Longest Valid Parentheses】cpp

    题目: Given a string containing just the characters '(' and ')', find the length of the longest valid ...

  4. Portion of class Throwable’s inheritance hierarchy

  5. 我是IT小小鸟

    我是IT小小鸟读后感 世界上没有一蹴而就的成功者,只有头悬梁锥刺股的奋斗者.蜉蝣向往大鹏的辉煌,却不曾知大鹏以往的汗水.蜉蝣之所以为蜉蝣,是因为它犹如井底之蛙,目光短浅,之盲目地羡慕成功者,而大鹏之所 ...

  6. hibernate缓存机制详细分析

    转自:http://www.cnblogs.com/xiaoluo501395377/p/3377604.html 在本篇随笔里将会分析一下hibernate的缓存机制,包括一级缓存(session级 ...

  7. JS中函数的基础知识

    函数 一.  函数定义 函数又叫方法,在程序里面函数是用来执行某些特定功能的代码.为了减少重复使用代码,可以把特定功能的代码做成函数,需要使用时拿出来调用.alert();就是一个很常见的.简单的函数 ...

  8. asp.net 认证与授权

    1.下面的例子在web.config文件中配置网站使用asp.net forms 身份认证方式: <configuration> <system.web> <authen ...

  9. JQuery拾遗

    1.关于JQuery的animate,可以操作background么? 答:如果是单纯的JQuery不可以,需要引入JQuery的ui核心库.否则只支持宽高.透明度.上下左右位置的变化. 2.能否说一 ...

  10. iOS打电话,发短信,发邮件,打开网址

    //调用自带mail [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@hzl ...