zoukankan      html  css  js  c++  java
  • POJ2485Highways(prime 水题)

    Highways
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 26516   Accepted: 12136

    Description

    The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning to build some highways so that it will be possible to drive between any pair of towns without leaving the highway system. 

    Flatopian towns are numbered from 1 to N. Each highway connects exactly two towns. All highways follow straight lines. All highways can be used in both directions. Highways can freely cross each other, but a driver can only switch between highways at a town that is located at the end of both highways. 

    The Flatopian government wants to minimize the length of the longest highway to be built. However, they want to guarantee that every town is highway-reachable from every other town.

    Input

    The first line of input is an integer T, which tells how many test cases followed. 
    The first line of each case is an integer N (3 <= N <= 500), which is the number of villages. Then come N lines, the i-th of which contains N integers, and the j-th of these N integers is the distance (the distance should be an integer within [1, 65536]) between village i and village j. There is an empty line after each test case.

    Output

    For each test case, you should output a line contains an integer, which is the length of the longest road to be built such that all the villages are connected, and this value is minimum.

    Sample Input

    1
    
    3
    0 990 692
    990 0 179
    692 179 0

    Sample Output

    692
    

    Hint

    Huge input,scanf is recommended.
    题意:最小生成树最大边
    渣英语让我对这道题的输出感到不解,刷了上题的prime之后这就是个水题了
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cstring>
     5 #include <string.h>
     6 using namespace std;
     7 const int INF = 10000000;
     8 const int MAX = 500 + 10;
     9 int g[MAX][MAX],vis[MAX],dist[MAX];
    10 
    11 int main()
    12 {
    13     int n,t;
    14     scanf("%d", &t);
    15     while(t--)
    16     {
    17         scanf("%d", &n);
    18         for(int i = 1; i <= n; i++)
    19         {
    20             for(int j = 1; j <= n; j++)
    21             {
    22                 scanf("%d", &g[i][j]);
    23             }
    24         }
    25         memset(dist,0,sizeof(dist));
    26         memset(vis,0,sizeof(vis));
    27         for(int i = 2; i <= n; i++)
    28             dist[i] = g[1][i];
    29         vis[1] = 1;
    30         int ans = 0;
    31         for(int i = 1; i < n; i++)
    32         {
    33             int minn = INF,pos;
    34             for(int j = 1; j <= n; j++)
    35             {
    36                 if(vis[j] == 0 && dist[j] < minn)
    37                 {
    38                     pos = j;
    39                     minn = dist[j];
    40                 }
    41             }
    42             ans = max(ans,minn);
    43             vis[pos] = 1;
    44             for(int j = 1; j <= n; j++)
    45             {
    46                 dist[j] = min(dist[j],g[pos][j]);
    47             }
    48         }
    49         printf("%d
    ",ans);
    50     }
    51 
    52     return 0;
    53 }
    View Code
  • 相关阅读:
    51nod 1412 AVL树的种类(经典dp)
    HDU 6141 I am your Father!(最小树形图+权值编码)
    POJ 3164 Command Network(最小树形图模板题+详解)
    HDU 6125 Free from square(状态压缩+分组背包)
    HDU 6143 Killer Names(容斥原理)
    CSU 1808 地铁(最短路变形)
    HDU 6128 Inverse of sum(同余)
    HDU 6121 Build a tree(完全K叉树)
    HDU 6129 Just do it(杨辉三角)
    HDU 6127 Hard challenge(扫描线)
  • 原文地址:https://www.cnblogs.com/zhaopAC/p/4978228.html
Copyright © 2011-2022 走看看