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.
     
     
     
  • 相关阅读:
    《MySQL入门很简单》练习7.4
    《MySQL入门很简单》练习6.9
    《MySQL入门很简单》练习6.6
    《MySQL入门很简单》练习6.5
    "mysql"不是内部或外部命令,也不是可运行的程序或批处理文件
    TControl与Windows消息
    TObject与消息分发
    长串
    使用TSplitter控件调整其他控件大小简便方法
    Cocos2d-x缓存机制(一)
  • 原文地址:https://www.cnblogs.com/lengxia/p/4387796.html
Copyright © 2011-2022 走看看