Posted: Thu Sep 14, 2006 4:42 am
Well, all the different kinds of IO have been covered here. If you email me your code, I can take a look.
Code: Select all
6
(2,2)
(1,1)
(8,6)
(9,7)
(8,3)
(9,4)
(9,9)
(1,1)
(1,1)
(9,9)
(8,4)
(9,5)
Code: Select all
DEBUG_LINE: steps : 1000030 (more than 50000)
DEBUG_LINE: steps : 809897 (more than 50000)
DEBUG_LINE: steps : 4713
DEBUG_LINE: steps : 88
DEBUG_LINE: steps : 16
DEBUG_LINE: steps : 29957
Code: Select all
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<algorithm>
using namespace std;
int tmp=0,count2=0,found=0,v[11][11];
pair <int,int> path[50001];
void dfs(int xi, int yi,int xe, int ye){
v[xi][yi] = 1;
count2++;
path[tmp++] = make_pair(xi,yi);
if(found) return;
if(count2-1>50000 || (xi==xe && yi==ye)){found=1; return;}
if(!v[xi-1][yi+1]&& !found){
dfs(xi-1,yi+1,xe,ye);
path[tmp++] = make_pair(xi,yi);
}
if(!v[xi+1][yi+1]&&!found){
dfs(xi+1,yi+1,xe,ye);
path[tmp++] = make_pair(xi,yi);
}
if(!v[xi+1][yi-1]&&!found){
dfs(xi+1,yi-1,xe,ye);
path[tmp++] = make_pair(xi,yi);
}
if(!v[xi-1][yi-1]&&!found){
dfs(xi-1,yi-1,xe,ye);
path[tmp++] = make_pair(xi,yi);
}
if(!found) {v[xi][yi]=0;count2++;}
}
void print(int xi, int yi, int xe, int ye){
for(int i=0;i<count2-1;i++)
printf("(%d,%d), ",path[i].first,path[i].second);
printf("(%d,%d)\n", path[count2-1].first, path[count2-1].second);
}
int main(){
int xi,yi,xe,ye,n;
char c[10];
scanf("%d", &n);
while(n--){
found=tmp=0;
count2=0;
memset(v,0,sizeof(v));
for(int i=0; i<=10;i++){
v[i][0] = 1;
v[0][i] = 1;
v[i][10] = 1;
v[10][i] = 1;
}
scanf("%s",c);
xi = c[1] -'0';
yi = c[3] -'0';
scanf("%s",c);
xe = c[1] -'0';
ye = c[3] -'0';
if((xe+ye-xi-yi) %2 !=0) printf("fail\n");
else dfs(xi,yi,xe,ye);
if(count2-1>50000) printf("more than 50000 steps\n");
else {print(xi,yi,xe,ye);}
if(n>0) printf("\n");
}
return 0;
}
Code: Select all
3
(1,1)
(9,9)
(1,1)
(3,1)
(1,1)
(2,1)
Code: Select all
(1,1), (2,2), (1,3), (2,4), (1,5), (2,6), (1,7), (2,8), (1,9), (2,8), (3,9), (4,8), (5,9), (6,8), (7,9), (8,8), (9,9)
(1,1), (2,2), (1,3), (2,4), (1,5), (2,6), (1,7), (2,8), (1,9), (2,8), (3,9), (4,8), (5,9), (6,8), (7,9), (8,8), (9,9), (8,8), (9,7), (8,6), (7,7), (6,6), (5,7), (4,6), (3,7), (4,6), (5,5), (6,4), (7,5), (8,4), (9,5), (8,4), (9,3), (8,2), (7,3), (6,2), (5,3), (4,4), (3,5), (4,4), (3,3), (4,2), (5,1), (4,2), (3,1)
fail