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
  • 相关阅读:
    CentOS 7.3报Centos7_Base库缺少GPG公钥
    nginx重写(隐藏)index.php目录
    工作经历简写
    Centos7.4安装htop
    nginx 超时时间配置说明
    c#中数据从数据库到客户端主要几种的导出方式(导出到excel,导出到word)
    C#操作word文档如何设置表格的行高
    Windows计划任务定时启动程序运行时发生错误的解决办法
    Asp.Net MVC中请求json文件时返回404 not found的解决办法
    Angularjs 如何自定义Img的ng-load 事件
  • 原文地址:https://www.cnblogs.com/zhaopAC/p/4978228.html
Copyright © 2011-2022 走看看