| ||||||||||
| 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 | |||||||||
麻烦大家给看看 这个为什么错了啊 DIS变种 谢谢了#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#define maxint 20000000
using namespace std;
double map[301][301];
double dis[301];
double x[301],y[301];
bool used[301];
int main()
{
int n,k=0;
while(scanf("%d",&n)==1&&n)
{
k++;
int i,j;
for(i=1;i<=n;i++)
scanf("%lf%lf",&x[i],&y[i]);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(i==j) map[i][j]=0;
else
{
map[i][j]=(x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]);
}
}
memset(used,false,sizeof(used));
for(i=1;i<=n;i++)
dis[i]=map[1][i];
used[1]=true;
int p;
for(p=1;p<n;p++)
{
int temp=maxint;
int u=0;
for(j=1;j<=n;j++)
{
if(used[j]==false&&dis[j]<temp)
{
u=j;
temp=dis[j];
}
}
used[u]=true;
for(j=1;j<=n;j++)
{
if(used[j]==false&&map[u][j]<maxint)
{
if(map[u][j]<dis[j])
dis[j]=map[u][j];
}
}
}
printf("Scenario #%d\n",k);
printf("Frog Distance = %.3lf\n\n",sqrt(dis[2]));
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator