POJ2488【DFS】
来源:互联网 发布:新疆网络屏蔽 编辑:程序博客网 时间:2024/04/29 21:12
阿西吧,搞清楚谁是行,谁是列啊!!!
#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>#include <iostream>using namespace std;#define LL __int64#define N 50int d[8][2]={{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}};bool vis[30][30];int xx[30];int yy[30];int flag;int a,b;void DFS(int x,int y,int num){ if(flag) return; if(num==a*b) { flag=1; for(int i=1;i<=num;i++) { printf("%c%d",xx[i]+64,yy[i]); } puts(""); //printf("%d\n",num); return; } for(int i=0;i<8;i++) { int aa=x+d[i][0]; int bb=y+d[i][1]; if(aa<1||bb<1||aa>b||bb>a||vis[bb][aa]) continue; vis[bb][aa]=1; xx[num+1]=aa; yy[num+1]=bb; DFS(aa,bb,num+1); vis[bb][aa]=0; }}int main(){ int T; scanf("%d",&T); int Case=1; for(Case=1;Case<=T;Case++) { scanf("%d%d",&a,&b); printf("Scenario #%d:\n",Case); flag=0; memset(vis,0,sizeof(vis)); xx[1]=1; yy[1]=1; vis[1][1]=1; DFS(1,1,1); if(!flag) { printf("impossible\n"); } puts(""); } return 0;}/*A1B3C1A2C1A2C1A2C1A2C1A2A1C2A3B1D2B3C1A2C3D1B2D3A1B3C1A2B4C2A3B1C3A4B2C4*/
0 0
- POJ2488 DFS
- poj2488(dfs)
- POJ2488【DFS】
- poj2488(dfs)
- poj2488(dfs)
- poj2488(经典dfs)
- POJ2488 骑士游历(DFS)
- poj2488~dfs基础题
- DFS—poj2488
- POJ2488 -- POJ1154-- DFS
- POJ2488 dfs回溯
- poj2488 DFS基础
- poj2488 dfs模版
- Knight's Journey(poj2488,dfs)
- POJ2488——简单DFS
- 2011.11.17 poj2488 dfs+回溯法
- POJ2488 A Knight's Journey(DFS)
- poj2488旧题重做标准DFS
- <crtdbg.h> 的作用
- JSESSIONID与SESSION
- 自定义圆形图
- CodeForces 653 A. Bear and Three Balls(数学 ,快排)
- Easy-题目8:242. Valid Anagram
- POJ2488【DFS】
- Eclipse Debug快捷键 和 SVN各个字母含义
- Easy-题目9:171. Excel Sheet Column Number
- Mybatis 入门之resultMap与resultType讲解实例
- excel中用当天日期命名工作表名vba
- JavaScript实现数据结构中的队列和堆栈
- 自定义spark udf计算单词的长度
- 排序——快速排序
- java5.30学习笔记