zoukankan      html  css  js  c++  java
  • POJ2485——Highways

    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.
    分析:最小生成树求最大权值~
    源码:
    #include<iostream>
    #include<string.h>
    #include<stdio.h>
    #include<ctype.h>
    #include<algorithm>
    #include<stack>
    #include<queue>
    #include<set>
    #include<math.h>
    #include<vector>
    #include<deque>
    #include<list>
    using namespace std;
    int n;
    int i,j;
    int map[550][550];
    bool mark[550];
    int prim()
    {
        int w=n;
        int k;
        int len;
        int max=-1;
        while(--w)
        {
            int min=999999;
            int y=0;
            for(i=2;i<=n;i++)
            {
                if(!mark[i]&&map[1][i]<min)
                {
                    min=map[1][i];
                    k=i;
                }
            }
            mark[k]=1;
            if(max<min)
            max=min;
            for(i=2;i<=n;i++)
            {
                if(!mark[i]&&map[k][i]<map[1][i])
                map[1][i]=map[k][i];
            }
        }
        return max;
    }
    int main()
    {
        int test;
        scanf("%d",&test);
        while(test--)
        {
            memset(map,0,sizeof(map));
            memset(mark,0,sizeof(mark));
            scanf("%d",&n);
            for(i=1; i<=n; i++)
                for(j=1; j<=n; j++)
                    scanf("%d",&map[i][j]);
                    printf("%d
    ",prim());
        }
        return 0;
    }
    


  • 相关阅读:
    go test 测试单个文件报错问题
    分布式应用异常测试一二说
    DevOps工程师到底做些什么?
    Devops高薪看这个就够了
    想使用Docker容器?先看看这些注意事项
    情景领导
    Robotium编写测试用例如何模拟Junit4的BeforeClass和AfterClass方法2
    Robotium编写测试用例如何模拟Junit4的BeforeClass和AfterClass方法1
    自己动手修改Robotium代码(下)
    自己动手修改Robotium代码(上)
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3296990.html
Copyright © 2011-2022 走看看