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 |
runtime error在哪裡?#include <cstdio> int N,E,SRow,SCol,comb=-1,prevComb=-1,progloc=-1; char **dir1, *step, **map; int **dir2, **prog; void nav(int row, int col, int prevRow, int prevCol){ prog[++progloc][0]=row; prog[progloc][1]=col; if (map[row][col]=='S' || map[row][col]=='+'){ if (row-1>=0 && !(row-1==prevRow) && (map[row-1][col]!='.') && (map[row-1][col]!='-')){ nav(row-1,col,row,col); } if (row+1<N && !(row+1==prevRow) && (map[row+1][col]!='.') && (map[row+1][col]!='-')){ nav(row+1,col,row,col); } if (col-1>=0 && !(col-1==prevCol) && (map[row][col-1]!='.') && (map[row][col-1]!='|')){ nav(row,col-1,row,col); } if (col+1<E && !(col+1==prevCol) && (map[row][col+1]!='.') && (map[row][col+1]!='|')){ nav(row,col+1,row,col); } } else if (map[row][col]=='-'){ if (col-1>=0 && !(col-1==prevCol) && (map[row][col-1]!='.') && (map[row][col-1]!='|')){ nav(row,col-1,row,col); } if (col+1<E && !(col+1==prevCol) && (map[row][col+1]!='.') && (map[row][col+1]!='|')){ nav(row,col+1,row,col); } } else if (map[row][col]=='|'){ if (row-1>=0 && !(row-1==prevRow) && (map[row-1][col]!='.') && (map[row-1][col]!='-')){ nav(row-1,col,row,col); } if (row+1<N && !(row+1==prevRow) && (map[row+1][col]!='.') && (map[row+1][col]!='-')){ nav(row+1,col,row,col); } } else if (map[row][col]=='E') comb++; else if (map[row][col]=='.') { progloc--; return; } if (comb>prevComb){ for (int i=0;i<progloc;i++){ prevRow=prog[i][0]; prevCol=prog[i][1]; row=prog[i+1][0]; col=prog[i+1][1]; if (col-prevCol==1){ //printf("%c",'E'); if (dir1[comb][step[comb]]=='E') dir2[comb][step[comb]]++; else { dir1[comb][++step[comb]]='E'; dir2[comb][step[comb]]++; } } else if (col-prevCol==-1){ //printf("%c",'W'); if (dir1[comb][step[comb]]=='W') dir2[comb][step[comb]]++; else { dir1[comb][++step[comb]]='W'; dir2[comb][step[comb]]++; } } else if (row-prevRow==1){ //printf("%c",'S'); if (dir1[comb][step[comb]]=='S') dir2[comb][step[comb]]++; else { dir1[comb][++step[comb]]='S'; dir2[comb][step[comb]]++; } } else if (row-prevRow==-1){ //printf("%c",'N'); if (dir1[comb][step[comb]]=='N') dir2[comb][step[comb]]++; else { dir1[comb][++step[comb]]='N'; dir2[comb][step[comb]]++; } } } prevComb=comb; } progloc--; } int main(){ scanf("%d %d",&N,&E); N=2*N-1; E=2*E-1; dir1=new char* [1200]; dir2=new int* [1200]; step=new char [1200]; for (int i=0;i<1200;i++){ dir1[i]=new char [1200]; dir2[i]=new int [1200]; } map=new char*[80]; for (int i=0;i<80;i++) map[i]=new char[80]; for (int i=0;i<N;i++) scanf("%s",map[i]); for (int i=0;i<N;i++){ int j; for (j=0;j<E;j++) if (map[i][j]=='S'){ SRow=i; SCol=j; break; } //if (map[i][j]=='S') break; } for (int i=0;i<N*E;i++){ for (int j=0;j<N*E;j++){ dir1[i][j]=' '; dir2[i][j]=0; } step[i]=-1; } prog=new int *[1200]; for (int i=0;i<1200;i++){ prog[i]=new int [2]; for (int j=0;j<2;j++) prog[i][j]=-1; } nav(SRow,SCol,-2,-2); int min=9999; int mincomb=-1; for (int i=0;i<=comb;i++){ int sum=0; for (int j=0;j<step[i];j++) sum+=dir2[i][j]; if (sum<min){ mincomb=i; sum=min; } } if (mincomb>-1) for (int i=0;i<=step[mincomb];i++){ printf("%c %d\n",dir1[mincomb][i],dir2[mincomb][i]/2); } //system("PAUSE"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator