| ||||||||||
| 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 | |||||||||
不知道哪里错了,哪位大牛帮你忙啊!找了一个下午都没有找出来,一直说是Wrong Answer#include<stdio.h>
#include<string.h>
int r,c;
typedef struct
{
char num_r;
int num_c;
}point;
point num[27];
int dx[8] = {-1, 1, -2, 2, -2, 2, -1, 1};
int dy[8] = {-2, -2, -1, -1, 1, 1, 2, 2};
char str[27][27];
int dfs(int t,int x,int y);
int main()
{
int i,n,t;
freopen("2488.txt","r",stdin);
scanf("%d",&t);
n=t;
while(n--)
{
scanf("%d%d",&r,&c);
memset(str,'*',sizeof(str));
memset(num,-1,sizeof(num));
str[0][0]='-';
num[0].num_r='A';
num[0].num_c=1;
int flag=dfs(0,0,0);
printf("Scenario #%d:\n",t-n);
if(flag==1)
{
i=0;
while(num[i].num_c!=-1)
{
printf("%c%d",num[i].num_r,num[i].num_c);
i++;
}
printf("\n");
}
else
printf("impossible\n");
printf("\n");
}
return 0;
}
int dfs(int t,int x,int y)
{
int flag;
while(t!=r*c-1)
{
flag=1;
for(int i=0;i<8;i++)
if(x+dx[i] >= 0 && x+dx[i] < r&&
y+dy[i] >= 0 && y+dy[i] < c&&
str[x+dx[i]][y+dy[i]]=='*'
)
{
flag=0;
str[x+dx[i]][y+dy[i]]='-';
num[++t].num_r='A'+y+dy[i];
num[t].num_c=x+dx[i]+1;
x+=dx[i];y+=dy[i];
break;
}
if(flag==1)
return 0;
}
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator