B - Highways

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,然后输入N行,每行N个数据,其实就是一个N*N的矩阵,i行j列代表第i个村子到第j个村子的距离,问在全部联通且权值和最小的情况下修的最长的道路,,,

思路:克鲁斯卡尔算法水过,注意读的时候只要读上半部分或者下半部分就可以了;

下面附上代码:

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int pre[550],zz[550],ma[550][550];
struct node
{
	int u,v,w;
}s[125010];
bool cmp(node a,node b)
{
	return a.w<b.w;
}
int find(int x)
{
	if(pre[x]==x)
		return x;
	return pre[x]=find(pre[x]);
}
void merge(int x,int y)
{
	int fx=find(x),fy=find(y);
	if(fx==fy)
		return ;
	if(zz[fx]<zz[fy]) pre[fx]=fy;
	else
	{
		pre[fy]=fx;
		if(zz[fx]==zz[fy]) zz[fx]++;
	}
}
int main()
{
	int t,n;
	cin>>t;
	int m;
	while(t--)
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			pre[i]=i;
			zz[i]=0;
		}
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				scanf("%d",&ma[i][j]);
		int l=0;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=i;j++)
			{
				if(i==j) continue;
				s[l].u=i;
				s[l].v=j;
				s[l].w=ma[i][j];
				l++;
			}
		}
		sort(s,s+l,cmp);
		int ans=0;
		for(int i=0;i<l;i++)
		{
			if(find(s[i].u)!=find(s[i].v))
			{
				ans=max(ans,s[i].w);
				merge(s[i].u,s[i].v);
			}
		}
		printf("%d\n",ans);
	}
	return 0; 
}






用r语言解决以下问题:Boston Housing Data. The Boston housing data set was collected by Harrison and Rubinfeld (1978). It comprise 506 observations for each census district of the Boston metropolitan area. The data set was analyzed in Belsley et al. (1980). • X1: per capita crime rate, • X2: proportion of residential land zoned for large lots, • X3: proportion of nonretail business acres, • X4: Charles River (1 if tract bounds river, 0 otherwise), • X5: nitric oxides concentration, • X6: average number of rooms per dwelling, • X7: proportion of owner-occupied units built prior to 1940, • X8: weighted distances to five Boston employment centers, • X9: index of accessibility to radial highways, • X10: full-value property tax rate per $10,000, • X11: pupil/teacher ratio, • X12: 1000(B−0.63)2 I(B < 0.63) where B is the proportion of African American, • X13: % lower status of the population, • X14: median value of owner-occupied homes in $1000. Car Data. The car data set Chambers et al. (1983) consists of 13 variables measured for 74 car types. The abbreviations in this section are as follows: • X1:P Price, • X2:M Mileage (in miles per gallone), • X3:R78 Repair record 1978 (5–point scale; 5 best, 1 worst), • X4:R77 Repair record 1977 (scale as before), • X5:H Headroom (in inches), • X6:R Rear seat clearance (distance from front seat back to rear seat, in inches), • X7:Tr Trunk space (in cubic feet), • X8:W Weight (in pound), 2 • X9:L Length (in inches), • X10:T Turning diameter (required to make a U-turn, in feet), • X11:D Displacement (in cubic inches), • X12:G Gear ratio for high gear, • X13:C Company headquarter (1 - U.S., 2 - Japan, 3 - Europe). Banknote Data. Six variables measured on 100 genuine and 100 counterfeit old Swiss 1000- franc bank notes. The data stem from Flury and Riedwyl (1988). The columns correspond to the following 6 variables: • X1: Length of the bank note, • X2: Height of the bank note, measured on the left, • X3: Height of the bank note, measured on the right, • X4: Distance of inner frame to the lower border, • X5: Distance of inner frame to the upper border, • X6: Length of the diagonal. Observations 1–100 are the genuine bank notes and the other 100 observations are the counterfeit bank notes. Job Applicants Data In this study, 48 individuals who had applied for a job with a large firm were interviewed and rated on 15 criteria. Individuals were rated on the form of their letter of application (FL), their appearance (APP), academic ability (AA), likability (LA), selfconfidence (SC), lucidity (LC), honesty(HON), salesmanship (SMS), experience (EXP), drive (DRV), ambition (AMB), ability to grasp concepts (GSP), potential (POT), keenness to join (KJ), and their suitability (SUIT). Each criterion was evaluated on a scale ranging from 0 to 10, with 0 being a very low and very unsatisfactory rating, and 10 being a very high rating.
最新发布
06-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值