zoukankan      html  css  js  c++  java
  • poj 2485 Highways

    Highways
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 24326   Accepted: 11229

    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
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <string>
     4 #include <queue>
     5 #include <stack>
     6 #include <iostream>
     7 using namespace std;
     8 #define lengthmax 65537
     9 int map[505][505];
    10 int dis[505];
    11 int main(){
    12     //freopen("D:\INPUT.txt","r",stdin);
    13     int t,n;
    14     scanf("%d",&t);
    15     while(t--){
    16         scanf("%d",&n);
    17         int i,j;
    18         for(i=0;i<n;i++){
    19             dis[i]=lengthmax;
    20             for(j=0;j<n;j++){
    21                 scanf("%d",&map[i][j]);
    22             }
    23         }
    24         int m=1,mink,s=0,min,want=-1;
    25         dis[0]=0;//已经在集合里面
    26         while(m<n){//循环n-1次
    27             min=lengthmax;
    28             for(i=1;i<n;i++){
    29                 if(dis[i]>map[s][i]){//更新
    30                     dis[i]=map[s][i];
    31                 }
    32                 if(dis[i]&&min>dis[i]){
    33                     min=dis[i];
    34                     mink=i;
    35                 }
    36             }
    37             //cout<<mink<<endl;
    38             //cout<<min<<endl;
    39             if(min>want){
    40                 want=min;
    41                 //cout<<want<<endl;
    42             }
    43             dis[mink]=0;
    44             s=mink;
    45             m++;
    46         }
    47         cout<<want<<endl;
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    开发笔记:python与随机数(转)
    如何建立内核级钩子控制操作系统实现程序隐身(转)
    SPOJ 7001. Visible Lattice Points (莫比乌斯反演)
    BZOJ 2301: [HAOI2011]Problem b (莫比乌斯反演)
    HDU 1695 GCD (莫比乌斯反演)
    HDU 4691 Front compression (2013多校9 1006题 后缀数组)
    HDU 4686 Arc of Dream (2013多校9 1001 题,矩阵)
    HDU 1695 GCD (欧拉函数+容斥原理)
    【转】[专题学习][计算几何]
    POJ 1755 Triathlon (半平面交)
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4644993.html
Copyright © 2011-2022 走看看