zoukankan      html  css  js  c++  java
  • 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.



    给出n个点分别到每个点的距离   给出的实例中的三行三个数字   分别是第一个点分别到第1 2 3个点的距离  第二个点到第1 . 2 3个点的距离  第三个点到第1 2 3 个点的距离      题目就是这么的迷人

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    struct node
    {
    	int f,to,val;
    }bian[100001];
    int pre[10001];
    int find(int p)
    {
    	while(p!=pre[p])
    	{
    		p=pre[p];
    	}
    	return p;
    }
    bool cmp(node a,node b)
    {
    	return a.val <b.val ;
    }
    int main()
    {
    	int t;
    	scanf("%d",&t);
    	while(t--)
    	{
    		int n,m,shu=0;;
    		scanf("%d",&n);
    		for(int i=1;i<=n;i++)
    		{
    			pre[i]=i;
    		}
    		for(int i=1;i<=n;i++)
    		{
    			for(int j=1;j<=n;j++)
    			{
    				scanf("%d",&m);
    				bian[shu].f =i;
    				bian[shu].to =j;
    				bian[shu].val =m;
    				shu++;
    			}
    		}
    		sort(bian,bian+shu,cmp);
    		int ma=0;
    		for(int i=0;i<shu;i++)
    		{
    			int fx=find(bian[i].f );
    			int fy=find(bian[i].to);
    			if(fx!=fy)
    			{
    				if(ma<bian[i].val )
    				{
    					ma=bian[i].val ;
    				}
    				pre[fx]=fy;
    			}
    		}
    		printf("%d
    ",ma);
    	}
    	return 0;
    }


  • 相关阅读:
    大数据量分表时 两个表查询比较快的方式
    开启SQL Server执行占用时间显示和逻辑读取次数显示
    【转】SQL Server海量数据库的索引、查询优化及分页算法
    Exchange无法发送邮件 未找到匹配的连接器来路由外部收件人解决办法
    HTML介绍&常用的标签
    关于HTML文件、JS文件、CSS文件
    python命名空间和作用域
    pymysql
    存储过程、视图、触发器、函数
    多表查询
  • 原文地址:https://www.cnblogs.com/kingjordan/p/12027092.html
Copyright © 2011-2022 走看看