Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

打楼上脸

Posted by fnoi16wjhui at 2018-01-30 20:34:30 on Problem 2560
In Reply To:数据只能是float类型否则你自己看着办! Posted by:chenxuan123456789 at 2012-09-09 10:11:21
这个程序就AC了
<~v~>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
struct node1{
	double x,y;
};
node1 a[110];
struct node{
	int x,y;double c;
};
node dic[5001];
int n,ans,f[110],xx,yy,num;double sum;
int get(int x){
	if(f[x]==0) return x;
	return f[x]=get(f[x]);
}
bool cmp(node x,node y){
	if(x.c<y.c) return true;
	return false;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%lf%lf",&a[i].x,&a[i].y);
	for(int i=1;i<n;++i)
		for(int j=i+1;j<=n;++j)
			dic[++num].x=i,dic[num].y=j,
			dic[num].c=(a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y);
	sort(dic+1,dic+num+1,cmp);
	ans=n;
	for(int i=1;i<=num;++i){
		xx=get(dic[i].x);yy=get(dic[i].y);
		if(xx!=yy){
			--ans;f[xx]=yy;sum+=sqrt(dic[i].c);
			if(ans<=1) break;
		}
	}
	printf("%.2lf",sum);
	return 0;
} 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator