湖南省第十届大学生计算机程序设计竞赛1511: 残缺的棋盘

 残缺的棋盘
Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 473  Solved: 163
[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
HINT
Source
湖南省第十届大学生计算机程序设计竞赛

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
int x1,x2,y2,x3,y3,y1;
int dir[8][2]= {0,1,0,-1,-1,0,1,0,1,1,1,-1,-1,1,-1,-1};
int mark[10][10];
struct nodes
{
        int x,y,m;
};
nodes node1,node2;
void bfs()
{
    queue<nodes> q;
    while(!q.empty())
        q.pop();
    node1.x=x1;
    node1.y=y1;
    node1.m=0;
    mark[x1][y1]=1;
    q.push(node1);
    while(!q.empty())
    {
        node1=q.front();
        q.pop();
        if(node1.x==x2&&node1.y==y2)
        printf("%d\n",node1.m);
        for(int i=0; i<8; i++)
        {
            node2.x=node1.x+dir[i][0];
            node2.y=node1.y+dir[i][1];
            if(node2.x>=1&&node2.x<=8&&node2.y>=1&&node2.y<=8&&!mark[node2.x][node2.y])
            {
                mark[node2.x][node2.y]=1;
                node2.m=node1.m+1;
                q.push(node2);
            }
        }
    }


}
int main()
{
    int k=0;
    while(~scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3))
    {
        k++;
        memset(mark,0,sizeof(mark));
        mark[x3][y3]=1;
        printf("Case %d: ",k);
        bfs();
    }
}

 

转载于:https://www.cnblogs.com/dshn/p/4750411.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值