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;
    }

  • 相关阅读:
    c# 大白话告诉你Thread的Sleep和Join的区别
    c# winform richtextbox控制每行颜色 + 滚动条始终滚动到最底部
    c# winform禁止窗口多开
    winform窗口关闭,进程没有关掉的解决办法
    System.Threading.Timer定时器使用注意事项
    c# socket 心跳 重连
    javascript 从对象数组中 按字段/属性取最大值或最小值
    codesmith设置mysql的连接字符串
    .net桌面程序或者控制台程序使用NLog时的注意事项
    vue获取不到后端返回的响应头
  • 原文地址:https://www.cnblogs.com/asuran/p/1577155.html
Copyright © 2011-2022 走看看