您的位置:首页 > 理论基础

湖南省大学生计算机程序设计竞赛(残缺的棋盘)

2016-08-05 16:27 155 查看


1511: 残缺的棋盘

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 680  Solved: 244

[Submit][Status][Web
Board]


Description




Input

输入包含不超过10000 组数据。每组数据包含6个整数r1, c1, r2, c2, r3, c3 (1<=r1, c1, r2, c2, r3, c3<=8). 三个格子A, B, C保证各不相同。


Output

对于每组数据,输出测试点编号和最少步数。


Sample Input

1 1 8 7 5 6
1 1 3 3 2 2


Sample Output

Case 1: 7
Case 2: 3


#include <iostream>
#include <stdio.h>
#include<queue>
#include<string.h>
using namespace std;
int sx,sy,ex,ey,nx,ny,rr,a[9][9],now[1000][2],nextt[1000][2],nex;
int h[8]= {-1,-1,-1,0,0,1,1,1},
l[8]= {-1,0,1,-1,1,-1,0,1};
void bfs(int x,int y)
{
for(int i=0; i<8; i++)
{
if(x+h[i]>=1&&x+h[i]<=8&&y+l[i]>=1&&
y+l[i]<=8&&a[x+h[i]][y+l[i]]==0)
{
if(x+h[i]==ex&&y+l[i]==ey)
rr=0;

a[x+h[i]][y+l[i]]=1;
nextt[nex][0]=x+h[i];
nextt[nex++][1]=y+l[i];
}
}

}
int main()
{
int u=0;
while(~scanf("%d%d%d%d%d%d",&sx,&sy,&ex,&ey,&nx,&ny))
{
memset(a,0,sizeof(a));
a[nx][ny]=1;
int no=1;
now[0][0]=sx;
now[0][1]=sy;

rr=1;
int oo=0;
while(rr)
{
nex=0;
for(int i=0; i<no; i++)
{
bfs(now[i][0],now[i][1]);
}
for(int i=0; i<nex; i++)
{
now[i][0]=nextt[i][0];
now[i][1]=nextt[i][1];
}
oo++;
no=nex;
}
printf("Case %d: %d\n",++u,oo);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐