zoukankan      html  css  js  c++  java
  • poj 2485 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
    
    求最小生成树中的最大数
    
    
    
    
    #include<iostream>
    #include <string.h>
    #include<stdio.h>
    using namespace std;
    int p[501][501],x,y,vis[501],i,j;
    int main()
    
    
    
    
    { int n,k,t;
    cin>>t;
    while (t--)
    {cin>>n;
        int max;
    	memset(p,0,sizeof(p));
    
    	for(i=1;i<=n;i++)
    		for(j=1;j<=n;j++)
    			cin>>p[i][j];
    		memset(vis,0,sizeof(vis));
    		vis[1]=1;
    
    		for(i=0;i<n-1;i++)
    		{ max=1000000;
    		for(j=1;j<=n;j++)
    		{if(!vis[j]&&p[1][j]<max)
    		{max=p[1][j];
    		x=j;}
    		}
    		vis[x]=1;
    		for(j=1;j<=n;j++)
    		{if(!vis[j]&&p[1][j]>p[x][j])
    		p[1][j]=p[x][j];
    
    
    		}
    		}
    
    for(k=1;k<=n;k++)
        if(p[1][k]>max)
        max=p[1][k];
    cout<<max<<endl;
    
    }
    return 0;}



     

    Hint

    Huge input,scanf is recommended.
     
     
     
  • 相关阅读:
    正则表达式之断言
    认识CSS中标题引入icon图标
    认识CSS中字体图标
    认识CSS中精灵技术(sprite)和滑动门
    认识CSS中高级技巧之用户界面样式
    认识CSS中高级技巧之元素的显示与隐藏
    认识CSS中布局之文档流、浮动、定位以及叠放次序
    正则表达式之括号
    正则表达式之量词
    正则表达式之字符组
  • 原文地址:https://www.cnblogs.com/lengxia/p/4387796.html
Copyright © 2011-2022 走看看