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 |
谁能帮忙看下哪错了吗。。。谢谢#include<stdio.h> #include<math.h> typedef struct { double x1; double y1; double x2; double y2; int col; double dis; }offset ; offset item[105]; int col[105]; double now[2][105][2]; double dist(double x1,double y1,double x2,double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } double min(double x,double y) { return (x<y)?x:y; } int main() { int cas,n,i,j,s,p,t,flag,k; double x,y,min_x,min_y,m,s_x,s_y,f_x,f_y; scanf("%d",&cas); while(cas--) { scanf("%lf%lf%lf%lf",&s_x,&s_y,&f_x,&f_y); scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&col[i]); scanf("%d",&t); for(i=1;i<=t;i++) { scanf("%lf%lf%lf%lf%d",&item[i].x1,&item[i].y1,&item[i].x2,&item[i].y2,&item[i].col); item[i].dis=dist(item[i].x1,item[i].y1,item[i].x2,item[i].y2); } s=0; p=1; for(i=1;i<=t;i++) if(item[i].col==col[1]) { now[s][i][0]=sqrt((s_x-item[i].x1)*(s_x-item[i].x1)+(s_y-item[i].y1)*(s_y-item[i].y1)); now[s][i][1]=sqrt((s_x-item[i].x2)*(s_x-item[i].x2)+(s_y-item[i].y2)*(s_y-item[i].y2)); } else { now[s][i][0]=-1; now[s][i][1]=-1; } for(i=2;i<=n;i++) { for(j=1;j<=t;j++) if(item[j].col==col[i]) { flag=0; for(k=1;k<=t;k++) if(item[k].col==col[i-1]) { x=min(now[s][k][0]+dist(item[k].x2,item[k].y2,item[j].x1,item[j].y1),now[s][k][1]+dist(item[k].x1,item[k].y1,item[j].x1,item[j].y1))+item[k].dis; y=min(now[s][k][0]+dist(item[k].x2,item[k].y2,item[j].x2,item[j].y2),now[s][k][1]+dist(item[k].x1,item[k].y1,item[j].x2,item[j].y2))+item[k].dis; if(flag==0) { min_x=x; min_y=y; flag=1; } else if(x<min_x) min_x=x; else if(y<min_y) min_y=y; } now[p][j][0]=min_x; now[p][j][1]=min_y; } else { now[p][j][0]=-1; now[p][j][1]=-1; } p=1-p; s=1-s; } flag=0; for(i=1;i<=t;i++) if(item[i].col==col[n]) { x=min(now[s][i][0]+dist(item[i].x2,item[i].y2,f_x,f_y),now[s][i][1]+dist(item[i].x1,item[i].y1,f_x,f_y))+item[i].dis; if(flag==0) { flag==1; m=x; } else if(x<m) m=x; } printf("%.3lf\n",m); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator