| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
wa啊,求大神指点#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator