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
  • 相关阅读:
    移动端性能优化动态加载JS、CSS
    右侧跟踪导航
    JQ+rotate插件实现图片旋转,兼容IE7+ CHROME等浏览器
    什么JSONP
    Web前端开发:什么是页面重回(repaints)与回流(reflow)
    javascript中的eval()函数应用以及要点
    SQL表值参数批量插入
    SQL SERVER 使用 OPENRORWSET(BULK)函数将txt文件中的数据批量插入表中(2)
    SQL SERVER 使用BULK Insert将txt文件中的数据批量插入表中(1)
    一个编程菜鸟的进阶之路(C/C++)
  • 原文地址:https://www.cnblogs.com/zhaopAC/p/4978228.html
Copyright © 2011-2022 走看看