zoukankan      html  css  js  c++  java
  • POJ 2485, Highways

    Time Limit: 1000MS  Memory Limit: 65536K
    Total Submissions: 6912  Accepted: 3284


    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.

    Source
    POJ Contest,Author:Mathematica@ZSU


    // POJ2485.cpp : Defines the entry point for the console application.
    //

    #include 
    <iostream>
    #include 
    <algorithm>
    using namespace std;

    int main(int argc, char* argv[])
    {
        
    int cases;
        scanf(
    "%d"&cases);

        
    int size;
        unsigned 
    short d[501][501];
        
    bool used[501];
        unsigned 
    short l[501];
        
    for (int c = 0; c < cases; ++c)
        {
            scanf(
    "%d"&size);
            
            
    for (int i = 0; i < size; ++i)
                
    for (int j = 0; j < size; ++j)
                {
                    scanf(
    "%d"&d[i][j]);
                };

            
    for (int i = 0; i < size; ++i) l[i] = d[0][i];

            memset(used, 
    0sizeof(used));
            used[
    0= true;
            
            
    for (int i = 1; i < size; ++i)
            {
                
    int len = 65535;
                
    int pos = 0;
                
    for (int j = 0; j < size; ++j)
                    
    if (used[j] == false && l[j] < len)
                    {
                        len 
    = l[j];
                        pos 
    = j;
                    };

                used[pos] 
    = true;
                
    for (int j = 0; j < size; ++j)
                    
    if (used[j] == false && l[j] > d[pos][j]) l[j] = d[pos][j];
            }
            cout 
    << *max_element(&l[0], &l[size])<<endl;
        }
        
    return 0;
    }

  • 相关阅读:
    基本配置+路由系统+模板
    ORM之SQLAlchemy
    web应用+250斗笔式模拟框架(socket、pymysql、jinja2)
    Leetcode56. Merge Intervals合并区间
    Leetcode50. Pow(x, n)(快速幂)
    Leetcode43. Multiply Strings字符串相乘(大数相乘)
    (转)Json在Unity中的简单使用
    Leetcode49. Group Anagrams字母异位词分组
    Leetcode48. Rotate Image旋转图像
    Leetcode47. Permutations II全排列2
  • 原文地址:https://www.cnblogs.com/asuran/p/1577155.html
Copyright © 2011-2022 走看看