| ||||||||||
| 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 | |||||||||
C++交AC,G++交WA,表示不造为啥!!!#include<stdio.h>
#include<string.h>
#include<math.h>
#define INF 0x3f3f3f3f
typedef struct
{
double x,y;
}nd;
nd node[105];
int visit[105],n;
double map[105][105],dis[105];
double jl(nd a,nd b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void prim()
{
double length=0,min;
int i,j,point=1;
for(i=1;i<=n;i++)
dis[i]=map[point][i];
memset(visit,0,sizeof(visit));
visit[point]=1;
for(i=1;i<n;i++)
{
min=INF;
for(j=1;j<=n;j++)
if(!visit[j]&&dis[j]<min)
{
min=dis[j];
point=j;
}
length+=min;
visit[point]=1;
for(j=1;j<=n;j++)
if(!visit[j]&&dis[j]>map[point][j])
dis[j]=map[point][j];
}
printf("%.2lf\n",length);
}
int main()
{
int i,j;
while(~scanf("%d",&n))
{
for(i=1;i<=n;i++)
{
scanf("%lf%lf",&node[i].x,&node[i].y);
for(j=1;j<=n;j++)
map[i][j]=map[j][i]=jl(node[i],node[j]);
map[i][i]=INF;
}
prim();
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator