poj 2488 A Knight's Journey
来源:互联网 发布:网络诈骗如何举报网站 编辑:程序博客网 时间:2024/05/22 16:55
PE。。 好无聊的题目。。
dfs一下就好的水题。。
#include<cstdio>#include<iostream>#include<queue>#include<set>#include<string>#include<cstring>#include<algorithm>using namespace std;int vis[10][10];int dis[8][2]={{2,1},{-2,1},{2,-1},{-2,-1},{1,2},{1,-2},{-1,2},{-1,-2}};set<string>q;char test[100010];int n,m;void dfs(int x,int y,int all){ if(all==(n*m)*2) { q.insert(test); } for(int i=0;i<8;i++) { int newx=x+dis[i][0]; int newy=y+dis[i][1]; if(newx<=0||newy<=0||newx>n||newy>m||vis[newx][newy]) { continue; } vis[newx][newy]=1; test[all+1]=newx+'0'; test[all]=newy+'A'-1; test[all+2]='\0'; dfs(newx,newy,all+2); vis[newx][newy]=0; }}int main(){ int T; cin>>T; int cnt=0; while(T--) { cin>>n>>m; memset(vis,0,sizeof(vis)); q.clear(); vis[1][1]=1; test[0]='A'; test[1]='1'; dfs(1,1,2); cout<<"Scenario #"<<++cnt<<":\n"; if(q.empty()) { cout<<"impossible"; } else cout<<*q.begin(); printf("\n"); if(T!= 0) printf("\n"); } return 0;}
0 0
- POJ 2488 A Knight's Journey
- POJ 2488 A Knight's Journey DFS
- Poj 2488 A Knight's Journey
- POJ 2488 A Knight's Journey (dfs)
- poj 2488 A Knight's Journey
- POJ 2488 A Knight's Journey
- POJ-2488-A Knight's Journey
- POJ 2488 A Knight's Journey
- poj 2488 A Knight's Journey
- poj 2488 A Knight's Journey
- POJ 2488 A Knight's Journey
- POJ 2488 A Knight's Journey
- poj 2488 A Knight's Journey
- poj 2488 A Knight's Journey
- POJ 2488 A Knight's Journey
- POJ 2488(A Knight's Journey)
- POJ 2488 A Knight's Journey
- POJ-2488-A Knight's Journey
- SASS如何实现PX转REM
- LeetCode 49. Group Anagrams
- postMessage()实现跨域
- c++实验4—星形图
- div中img显示问题
- poj 2488 A Knight's Journey
- android shape浅析
- 【SSH】Java之静态代理和动态代理
- Holding Bin-Laden Captive! hdoj 1085 (母函数初学,其他简便方法)
- 二.I/O模型
- 轻松解决mscorsvw.exe进程CPU占用高的问题
- C++不定参数的应用[转载]
- swift设计模式学习二
- 设计模式六大原则(1):单一职责