| ||||||||||
| 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提交就对,用C++就WA呢??//============================================================================
// Name : 2253.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C, Ansi-style
//============================================================================
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define maxn 205
#define inf 99999999
int pointx[maxn],pointy[maxn];
int dist[maxn][maxn];
int lowest[maxn];
int vis[maxn];
int n;
int getdist(int i,int j)
{
return (pointx[i]-pointx[j])*(pointx[i]-pointx[j])+(pointy[i]-pointy[j])*(pointy[i]-pointy[j]);
}
int prim()
{
int i,j,k=0,res = 0;//k当前要加入到最小生成树里的点的下标
memset(vis,0,sizeof(vis));
for(i=0;i<n;i++)
lowest[i] = inf;
lowest[k] = 0;
vis[k]=1;
while(k!=1)
{
int tmpmin = inf;
for(i=0;i<n;i++)
if(!vis[i]&&dist[k][i]<lowest[i])
lowest[i] = dist[k][i];
for(i=0;i<n;i++)
if(!vis[i]&&lowest[i]<tmpmin)
{
tmpmin = lowest[i];
k = i;
}
vis[k] = 1;
if(tmpmin>res)
res = tmpmin;
}
return res;
}
int main()
{
int i,j,ncase=0;
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif
while(scanf("%d",&n)&&(n!=0))
{
memset(pointx,0,sizeof(pointx));
memset(pointy,0,sizeof(pointy));
memset(dist,0,sizeof(dist));
for(i=0;i<n;i++)
scanf("%d%d",&pointx[i],&pointy[i]);
for(i=1;i<n;i++)
{
for(j=0;j<i;j++)
dist[i][j] = dist[j][i] = getdist(i,j);
dist[i][i] = 0;
}
printf("Scenario #%d\n",++ncase);
printf("Frog Distance = %.3lf\n\n",sqrt(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