POJ2488解题报告
来源:互联网 发布:郑州北京百知尚行科技 编辑:程序博客网 时间:2024/05/21 13:58
这道题啊 。 。不说啥了 ~数据量很小,暴力深搜,不需要啥剪枝就能过。
代码如下:
#include <iostream>
using namespace std;
const int xp[8]={-2,-2,-1,-1,1,1,2,2};
const int yp[8]={-1,1,-2,2,-2,2,-1,1};
struct node
{
int px,py;
};
int n,p,q,tot,t=0;
node d[27];
bool flag,map[26][26];
void dfs(int x,int y,int sum)
{
int tx,ty,i,k;
map[x][y]=true;
d[sum].px=x;
d[sum].py=y;
if(sum==p*q)
{
flag=true;
cout<<"Scenario #"<<t<<":"<<endl;
for(k=1;k<=tot;k++)
cout<<(char)(d[k].px+'A')<<d[k].py+1;
cout<<endl;
cout<<endl;
return;
}
else
{
for(i=0;i<8;i++)
{
tx=x+xp[i];
ty=y+yp[i];
if(tx<0||tx>=q)
continue;
if(ty<0||ty>=p)
continue;
if(map[tx][ty])
continue;
dfs(tx,ty,sum+1);
}
}
d[sum].px=0;
d[sum].py=0;
map[x][y]=false;
}
int main()
{
int i,j;
cin>>n;
while(n--)
{
t++;
cin>>p>>q;
tot=p*q;
memset(map,false,sizeof(map));
flag=false;
for(i=0;i<q;i++)
{
if(flag)
break;
for(j=0;j<p;j++)
{
memset(d,0,sizeof(d));
dfs(i,j,1);
if(flag)
break;
}
}
if(!flag)
{
cout<<"Scenario #"<<t<<":"<<endl;
cout<<"impossible"<<endl;
cout<<endl;
}
}
return 0;
}
- POJ2488解题报告
- POJ2488解题报告
- poj2488 DFS马棋环游 解题报告
- 【POJ2488】 A knight's Journey 解题报告 测试数据+代码+思路
- POJ2488 骑士游历 A Knight's Journey 解题报告
- POJ2488/openjudge 1490 A Knight's Journey 解题报告(dfs)
- poj2488
- POJ2488
- poj2488
- poj2488
- poj2488
- poj2488
- poj2488
- poj2488
- poj2488
- poj2488
- poj2488
- poj2488
- 【摘自csdn】默默的过好自己,没有人会在乎你
- UVa 10115 Automatic Editing
- 谈谈Session丢失的问题
- 30个被风投看重的网络创业点子
- 冲突域,冲突,广播域,广播
- POJ2488解题报告
- 痛苦的决择
- Axis简介及安装
- 制作不规则窗体哪有那么困难(MFC)
- 为什么免费是互联网的主流
- 在firefox与IE下DIV+CSS Padding效果不同的解决方法
- Fckedit 超链接中文乱码
- javascript中获取一个字符串中 特定字符串的个数
- div+css使用!important标记实现Firefox和IE6处理padding尺寸上的兼容