| ||||||||||
| 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<stdlib.h>
int p,q,T;
int classchess[27][27];
int path[1000][2];int top=0;
int move[8][2]={{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}};
int first; //first==1 means if finded ,it is first!
int diff='A'-0;
void DFS(int i,int j,int total) //i ,j 是将要访问的,total是有还多少没有访问(不包括将要的)?
{
int k;
int go_i,go_j;
/*int x,y;
int base;
char dir=t+1;
if(dir=='A'+q)
dir='A';
if(dir=='A'+q)
base=2;
else
base=0;
int x,y;
if(show==1)
{
/*/
/*printf(" i j is %d %d\n",i,j);
for(x=0;x<q;x++)
{
printf("\n");
for(y=0;y<p;y++)
printf("%d",classchess[x][y]);
}
printf("\n");
//_sleep(200);
*/
if(classchess[i][j]==0&&first==1)
if(total==1)
{
path[top][0]=i+diff;
path[top][1]=j+1;
classchess[i][j]=1;
top++;
//printf("first is %d\n",first);
if(first==1)
{
first=0;
for(i=0;i<top;i++)
{
printf("%c%d",path[i][0],path[i][1]);
}
printf("\n");
}
classchess[i][j]=0;
top--;
}
else
{
path[top][0]=i+diff;
path[top][1]=j+1;
top++;
classchess[i][j]=1;
for(k=0;k<8;k++)
{
//if(i==0&&j==0)
//printf("move is %d%d\n",move[k][0],move[k][1]);
go_i=i+move[k][0];go_j=j+move[k][1];
if(go_i>=0&&go_i<q&&go_j>=0&&go_j<p)
{
DFS(go_i,go_j,total-1);
}
}
classchess[i][j]=0;
top--;
}
}
void processACase(int number)
{
int i,j;
scanf("%d %d",&p,&q);
first=1;
for(i=0;i<p;i++)
for(j=0;j<q;j++)
classchess[i][j]=0;
printf("Scenario #%d:\n",number);
DFS(0,0,p*q);
if(first==1)
{
printf("impossible\n");
}
printf("\n");
}
int main()
{
int i;
scanf("%d",&T);
for(i=0;i<T;i++)
processACase(i+1);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator