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 |
同志们,帮忙看看这个该死的RE的程序咧,我实在不知道哪里出问题了~~呜呜#include<stdio.h> #include<string.h> char handle[5][4]; int top,tail; char temp_handle[5][4]; struct myquen { int row; int col; int step; int val; int flag; int last; }; struct myquen quen[65528]; int value(char temp[][4]) { int i,j; int number=0; for(i=0;i<4;i++) for(j=0;j<4;j++) number=number*2+temp[i][j]-'0'; return number; } int reverse(int number,int min) { int i,j,k; int temp=number; for(i=3;i>=0;i--) { for(j=3;j>=0;j--) { handle[i][j]=temp%2+'0'; temp=temp/2; } } for(i=0;i<4;i++) { for(j=0;j<4;j++) { for(k=0;k<4;k++) strcpy(temp_handle[k],handle[k]); for(k=0;k<4;k++) { temp_handle[i][k]='1'-handle[i][k]+'0'; temp_handle[k][j]='1'-handle[k][j]+'0'; } temp_handle[i][j]='1'-handle[i][j]+'0'; temp=value(temp_handle); if(quen[temp].flag==0) { quen[top].val=temp; quen[top].step=min+1; quen[temp].last=number; quen[temp].row=i; quen[temp].col=j; quen[temp].flag=1; if(temp==65535) return 1; top++; } } } return 0; } void Quen() { int token=0; while(1) { token=reverse(quen[tail].val,quen[tail].step); if(token==1 ) break; tail++; } } void solved() { int number=value(handle); if(number==65535) return; else if(quen[number].flag==0) { quen[top].val=number; top++; quen[number].flag=1; Quen(); } } int main() { int i,j; char token; int result,temp; int step[16][2]; i=0; top=0; tail=0; memset(quen,0,sizeof(quen)); for(i=0;i<4;i++) { for(j=0;j<4;j++) { scanf("%c",&token); if(token=='+') handle[i][j]='0'; else if(token=='-') handle[i][j]='1'; } getchar(); } solved(); result=quen[top].step; printf("%d\n",result); temp=quen[top].val; for(i=0;i<result;i++) { step[i][0]=quen[temp].row+1; step[i][1]=quen[temp].col+1; temp=quen[temp].last; } for(i=result-1;i>=0;i--) printf("%d %d\n",step[i][0],step[i][1]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator