poj1101 The Game
来源:互联网 发布:彩虹六号对局数据查询 编辑:程序博客网 时间:2024/04/30 03:55
#include<iostream>
using namespace std;
#define MAX 2*60000
int turn[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct Point
{
int x,y;
}queue[MAX],pre[6000];
bool mk[110][110];
int map[110][110];
int counts[110][110];
int n,m;
int BFS(int x,int y,int x2,int y2)
{
int front=0,rear=0;
int i;
int a,b;
memset(mk,false,sizeof(mk));
memset(counts,0,sizeof(counts));
mk[x][y]=true;
queue[rear].x=x;
queue[rear].y=y;
rear++;
while(front<rear)
{
x=queue[front].x;
y=queue[front].y;
front++;
for(i=0;i<4;i++)
{
a=x+turn[i][0];
b=y+turn[i][1];
while(!mk[a][b] && map[a][b] && a>=0 && a<=m+1 && b>=0 && b<=n+1)
{
mk[a][b]=true;
counts[a][b]=counts[x][y]+1;
if(a==x2 && b==y2)
return 1;
queue[rear].x=a;
queue[rear].y=b;
rear++;
a+=turn[i][0]; //别人的思想
b+=turn[i][1];
}
}
}
return 0;
}
int main()
{
int i,j,count=1;
int x,y,x1,y1;
int t1,t2,ant,cnt;
bool flag;
char ch;
while(1)
{
scanf("%d%d",&n,&m);
if(n==0 && m==0)
break;
for(i=0;i<=80;i++)
for(j=0;j<=80;j++)
map[i][j]=1;
for(i=1;i<=m;i++)
{
getchar();
for(j=1;j<=n;j++)
{
while(scanf("%c",&ch)&& ch!='X' && ch!=' ');
if(ch=='X')
map[i][j]=0;
}
}
i=1;
flag=true;
while(1)
{
scanf("%d%d%d%d",&x,&y,&x1,&y1);
if(x==0 && y==0 && x1==0 && y1==0)
break;
cnt=0;
t1=map[y][x];
t2=map[y1][x1];
map[y][x]=1;
map[y1][x1]=1;
if(flag)
{
printf("Board #%d:/n",count);
flag=false;
}
ant=BFS(y,x,y1,x1);
if(ant)
{
printf("Pair %d: %d segments./n",i,counts[y1][x1]);
}
else
printf("Pair %d: impossible./n",i);
map[y][x]=t1;
map[y1][x1]=t2;
i++;
}
printf("/n");
count++;
}
return 0;
}
- poj1101 The Game
- 【poj1101】The Game BFS
- poj1101-The Game(BFS)
- poj1101——The Game//优先队列
- poj1101
- poj1101
- poj1101
- poj1101
- The Game
- The Game
- The Game
- The Game
- poj1101解题报告
- poj1101广搜
- poj1101和openjudge 小游戏
- The Computer Game Dogma
- fjnu 1083 The Game
- The four number game
- 做自己
- LVS学习笔记(三)
- Alfresco:全球企业级系统应用软件第二次调查
- 随机化算法及随机数的产生
- 回忆:某年的某一天
- poj1101 The Game
- [分享] 3.0几个盗贼用得到的宏
- 冰舞使用介绍(强烈BS用于攻击别人网站的人,我就是爱害者)
- linux入门系统安装常见问题整理
- Direct3D 开发框架
- 用CSS来控制图片显示大小
- 分布式信息认知观
- .NET邮件的收发
- 冰舞使用方法(网站给人攻击了,找找漏洞)