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 |
为什么在这里AC,然后在ZOJ提交会出现Segmentation Fault 郁闷了!#include <cstdio> #include <cmath> #define MAXN 1000 const double inf = 1e99; using namespace std; double g[MAXN][MAXN],x[MAXN],y[MAXN],d[MAXN]; bool final[MAXN]; int n; int main() { int i,j,v; double dis,min; freopen("c:\\in.txt","r",stdin); for (i=0;i<MAXN;i++) for (j=0;j<MAXN;j++) g[i][j] = (i==j?0.0:inf); scanf("%lf%lf%lf%lf",&x[0],&y[0],&x[1],&y[1]); n=2; while(scanf("%lf%lf",&x[n],&y[n])!=EOF) { n++; while(true) { scanf("%lf%lf",&x[n],&y[n]); if (x[n]==-1&&y[n]==-1) break; g[n-1][n] = g[n][n-1] = sqrt((x[n]-x[n-1])*(x[n]-x[n-1])+(y[n]-y[n-1])*(y[n]-y[n-1]))/40000.0*60.0; n++; } } //计算需要步行的点对 for (i=0;i<n;i++) for (j=i+1;j<n;j++) { dis = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))/10000.0*60.0; if (dis<g[i][j]) g[i][j]= g[j][i] = dis; } //Dijkstra for (i=0;i<n;i++) { final[i] = false; d[i] = g[0][i]; } final[0] = true; v = 0; for (i=1;i<n;i++) { min = inf; for (j=0;j<n;j++) if (!final[j]&&d[j]<min) { v = j; min = d[j]; } final[v] = true; for (j=0;j<n;j++) if (!final[j]&&(min+g[v][j]<d[j])) d[j] = min+g[v][j]; } printf("%d\n",int(d[1]+0.5)); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator