CSU 1511の欠けた碁盤


Input
10000セット以下のデータを入力します.各データ群は、6個の整数r 1,c 1,r 2,c 2,r 3,c 3(1<=r 1,c 1,r 2,c 2,r 3,c 3<=8)を含む.3つの格子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   
#include   
#include   
using namespace std;  
#include   
#include   
int map[205][205];  
int vis[205][205];  
int dir[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,-1},{1,1},{-1,1},{-1,-1}};
int s1,e1,x2,y2;  
struct node  
{  
    int x,y;  
    int step;  
}  
;  
bool check(int x,int y)  
{  
    if(x>8 || y>8 ||x<1 ||y<1 )  
        return 1;  
    if(x==x2 &&y==y2)  
        return 1;  
    if(vis[x][y])  
        return 1;  
    return 0;  
}  
int bfs(int x,int y)  
{  
    int i;  
    queueq;  
    node st,ed;  
    st.x=x;  
    st.y=y;  
    st.step=0;  
    q.push(st);  
    while(!q.empty())  
    {  
        st=q.front();  
        q.pop();  
        if(st.x==s1 &&st.y==e1)  
            return st.step; 
        for(i=0;i<8;i++)  
        {  
            ed.x=st.x+dir[i][0];  
            ed.y=st.y+dir[i][1];  
            if(check(ed.x,ed.y))  
                continue;  
            ed.step=st.step+1;  
            vis[ed.x][ed.y]=1;  
            q.push(ed);  
        }  
    }  
}  
int main()  
{  
    int s,e,i,j;  
    int Case=0;  
    while(scanf("%d%d%d%d%d%d",&s,&e,&s1,&e1,&x2,&y2)!=EOF)  
    {   
        memset(vis,0,sizeof(vis));  
        vis[s][e]=1;  
        int ans=bfs(s,e);  
        printf("Case %d: ",++Case);  
        printf("%d
",ans); } return 0; }