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 }
  • 相关阅读:
    react 安装脚手架过程
    微信小程序-分享功能
    echarts 实现多图联动显示tooltip
    dom 相同父节点查找
    js 给你一个 32 位的有符号整数 x ,返回将 x 中的数字部分反转后的结果
    vue手写el-form组件
    vue组件传值、通信
    vue项目打包桌面应用 exe程序 以及打包为安装程序exe
    vue 使用echarts来制作图表
    前端数据可视化插件-图表
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4644993.html
Copyright © 2011-2022 走看看