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

  • 相关阅读:
    Spring MVC之LocaleResolver(解析用户区域)
    java.net.MalformedURLException: unknown protocol: c 这个错一般有两种原因导致: 1、URL协议、格式或者路径错误,
    ServletContext作用功能详解
    javax ee常用类
    前端控制器是整个MVC框架中最为核心的一块,它主要用来拦截符合要求的外部请求,并把请求分发到不同的控制器去处理,根据控制器处理后的结果,生成相应的响应发送到客户端。前端控制器既可以使用Filter实现(Struts2采用这种方式),也可以使用Servlet来实现(spring MVC框架)。
    随着时间的推移:构造SDK路径错误(An error occurred while automatically activating bundle com.android.ide.eclipse.adt)
    Smack+Openfire 接收和发送文件
    AVL旋转树
    创建一个数据库快照
    Mysql事务处理
  • 原文地址:https://www.cnblogs.com/asuran/p/1577155.html
Copyright © 2011-2022 走看看