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 |
发一段雷人代码(563ms过)#include <stdio.h> #include <memory.h> int main() { int tt,m,wide; int start[2],end[2]; int step,i,j,k; int map[305][305][2]; short stp; scanf("%d",&tt); for(m = 0; m < tt; m ++) { step = 0; scanf("%d",&wide); scanf("%d%d",&start[0],&start[1]); scanf("%d%d",&end[0],&end[1]); for(i = 0; i < wide + 4; i ++) { for(j = 0; j < wide + 4; j ++) { map[i][j][0] = map[i][j][1] = 0; } } map[start[0] + 2][start[1] + 2][0] = 1; k = 0; stp = 0; while(1) { for(i = 2; i < wide + 2; i ++) { for(j = 2; j < wide + 2; j ++) { if(map[i][j][k] == 1) { if(i == end[0] + 2 && j == end[1] + 2) { stp = 1; break; } map[i - 2][j + 1][1 - k] = 1; map[i + 2][j + 1][1 - k] = 1; map[i - 2][j - 1][1 - k] = 1; map[i + 2][j - 1][1 - k] = 1; map[i + 1][j - 2][1 - k] = 1; map[i - 1][j - 2][1 - k] = 1; map[i + 1][j + 2][1 - k] = 1; map[i - 1][j + 2][1 - k] = 1; } } if(stp) break; } if(stp) break; for(i = 2; i < wide + 2; i ++) { for(j = 2; j < wide + 2; j ++) { map[i][j][k] = 0; } } k = 1 - k; step ++; } printf("%d\n",step); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator