| ||||||||||
| 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 | |||||||||
为什么我在新版poj提交就wa了,可是在旧版提交就直接过了呢代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct {int r; char c;}point;
int visit[50][50];
int dirr[50] = {-1, 1, -2, 2, -2, 2, -1, 1};
int dirc[50] = {-2, -2, -1, -1, 1, 1, 2, 2};
int find, step;
point path[2500];
int p, q;
void dfs(int i, int j);
int main()
{
int n, t = 0, midp, i, j;
scanf("%d", &n);
memset(visit, 0, sizeof (visit));
while (n--)
{
t++;
find = 0;
scanf("%d%d", &p, &q);
printf("Scenario #%d:\n", t);
/*if (p % 2 == 0)
{
midp = p / 2;
}
else
{
midp = p / 2 + 1;
}*/
for (j=1; j<=q; j++)
{
for (i=1; i<=p; i++)
{
step = 1;
path[step].r = i;
path[step].c = j + 'A' - 1;
visit[i][j] = 1;
dfs(i, j);
visit[i][j] = 0;
if (find)
{
break;
}
}
if (find)
{
break;
}
}
if (find == 0)
{
printf("impossible");
}
printf("\n\n");
}
system("pause");
return 0;
}
void dfs(int i, int j)
{
int r, c, count;
if (find == 0)
{
if (step == p * q)
{
find = 1;
for (count=1; count<=step; count++)
{
printf("%c%d", path[count].c, path[count].r);
}
}
else if (step != p * q)
{
for (count=0; count<=7; count++)
{
r = i + dirr[count];
c = j + dirc[count];
if (r >= 1 && r <= p && c >= 1 && c <= q && visit[r][c] == 0)
{
step++;
path[step].r = r;
path[step].c = c + 'A' - 1;
visit[r][c] = 1;
dfs(r, c);
step--;
visit[r][c] = 0;
}
}
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator