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

wa啊,求大神指点

Posted by zyzbdyldysl at 2014-07-03 16:50:21 on Problem 2560
#include<iostream>
#include<vector>
#include<set>
#include<cstdio>
#include<math.h>
using namespace std;
#define Infinity 0xffffffff
#define eps 1e-8
int main()
{
	int n;
	while (cin >> n)
	{
		vector<pair<float, float> >loc;
		set<pair<float, float> > in;
		for (int i = 0; i < n; i++)
		{
			double x, y;
			cin >> x >> y;
			loc.push_back(pair<float, float>(x, y));
		}
		double result = 0.0;
		in.insert(loc[0]);
		int locnow;
		while (in.size() != n)
		{
			double min = Infinity;
			set<pair<float, float> > ::iterator it;
			vector<pair<float, float> > ::iterator minit;
			vector<pair<float, float> > ::iterator it2;
			for (it = in.begin(); it != in.end(); it++)
			{
				for (it2 = loc.begin(); it2 != loc.end(); it2++)
				{
					if (in.count(*it2) == 0)
					{
						double dis;
						dis = sqrt(((*it).first - (*it2).first)*((*it).first - (*it2).first) + 
							((*it).second - (*it2).second)*((*it).second - (*it2).second));
						if (dis < min)
						{
							min = dis;
							minit = it2;
						}
					}
				}
			}
			in.insert(*it2);
			loc.erase(minit);
			result += min;
		}
		printf("%.2f\n",result);
	}
}

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