poj2488 2010.2.20
来源:互联网 发布:夺宝app源码 编辑:程序博客网 时间:2024/06/14 11:33
poj2488 2010.2.20
#include <stdio.h>#include <string.h>typedef struct node{int r;int c;}node;node step[50];int m,n,found;int dx[]={-2,-2,-1,-1,1,1,2,2},dy[]={-1,1,-2,2,-2,2,-1,1};int visited[50][50],dep;int ok(int r,int c){if (r>=1&&r<=m&&c>=1&&c<=n) return 1;return 0;}void output(){int i;if (found==0){printf("impossible\n\n");return ;}for(i=1;i<=m*n;i++)printf("%c%d",(step[i].r)+'A'-1,step[i].c);printf("\n\n");}void solve(int r,int c){if (!found){visited[r][c]=1;step[dep].r=r;step[dep].c=c;if (dep>=m*n){found=1;return;}else{int nextr,nextc,i;for(i=0;i<8;i++){nextr=r+dx[i];nextc=c+dy[i];if (ok(nextr,nextc)&&!visited[nextr][nextc]){dep++;solve(nextr,nextc);dep--;}}visited[r][c]=0;}}}int main(){int T,count=1;scanf("%d",&T);while (count<=T){scanf("%d %d",&n,&m);dep=1;found=0;memset(visited,0,sizeof(visited));solve(1,1);printf("Scenario #%d:\n",count);output();count++;}return 0;}
0 0
- poj2488 2010.2.20
- poj2488
- POJ2488
- poj2488
- poj2488
- poj2488
- poj2488
- poj2488
- poj2488
- poj2488
- poj2488
- poj2488
- poj2488
- Poj2488
- poj2488
- poj2488
- poj2488
- poj2488
- [Java视频笔记]day09
- Android 获取屏幕的宽度和高度
- apache commons io 2.2(一)Comparator部分
- Linux Mint使用Thunderbird必不可少的系统托盘插件
- 【POI2008】【BZOJ1132】Tro
- poj2488 2010.2.20
- cest
- 第一届蓝桥杯C/C++组编程题2 兑换纸币
- poj2056 2010.2.20
- ASP.NET List泛型分页代码
- 107. Binary Tree Level Order Traversal II
- poj1200 2010.2.20
- Python ConfigParser的使用
- 1003. 我要通过!