POJ 2488 A Knight's Journey
2014-09-07 22:15
148 查看
A Knight's Journey
Time Limit: 1000msMemory Limit: 65536KB
This problem will be judged on PKU. Original ID: 2488
64-bit integer IO format: %lld Java class name: Main
Background
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <vector> #include <queue> #include <cstdlib> #include <string> #include <set> #include <stack> #define LL long long #define pii pair<int,int> #define INF 0x3f3f3f3f using namespace std; const int dir[8][2] = {{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}}; int n,m,path[100][2]; bool vis[100][100]; bool dfs(int x,int y,int cur){ if(cur >= n*m) return true; for(int i = 0; i < 8; i++){ int tx = dir[i][0]+x; int ty = dir[i][1]+y; if(tx < 0 || tx >= n || ty < 0 || ty >= m || vis[tx][ty]) continue; vis[tx][ty] = true; path[cur][0] = tx+'A'; path[cur][1] = ty+1; if(dfs(tx,ty,cur+1)) return true; vis[tx][ty] = false; } return false; } int main() { int t,k = 1; scanf("%d",&t); while(t--){ scanf("%d %d",&m,&n); bool flag = false; memset(vis,false,sizeof(vis)); path[0][0] = 'A'; path[0][1] = 1; vis[0][0] = true; printf("Scenario #%d:\n",k++); if(dfs(0,0,1)){ for(int i = 0; i < n*m; i++) printf("%c%d",path[i][0],path[i][1]); puts(""); }else puts("impossible"); puts(""); } return 0; }
View Code
相关文章推荐
- POJ-2488 A Knight's Journey (DFS)
- POJ2488-A Knight's Journey(DFS)
- POJ2488 A Knight's Journey(DFS)
- POJ 2488:A Knight's Journey
- POJ 2488 A Knight's Journey
- poj2488--------------深搜(注意字典序)
- poj 2488( 搜索 )
- 广大暑假训练1(poj 2488) A Knight's Journey 解题报告
- A Knight's Journey (poj 2488 DFS)
- POJ 2488 A Knight's Journey
- poj 2488 dfs+回溯
- poj 2488 A Knight's Journey
- POJ 2488 A Knight's Journey
- DFS poj2488 A Knight's Journey
- poj2488骑士之旅
- POJ 2488 A Knight's Journey
- POJ 2488 A Knight's Journey
- poj 2488 dfs
- poj 2488 A Knight's Journey (dfs)
- POJ 2488 A Knight's Journey