# Incomplete Chessboard

Incomplete ChessboardInchess,Kingisthemostimportantpiece.Itcanmoveleft,right,up,downordiagonally,butonly onesquareatatime,shownbelow.

In chess, King is the most important piece. It can move left, right, up, down or diagonally, but only

one square at a time, shown below. Given two squares A(r1,c1), B(r2,c2), your task is to calculate the number of moves needed to move a
king from A to B. To make the problem (slightly) harder, one square C(r3,c3) is removed from the
chessboard, that means the king should never go into square C during his trip. In this problem, rows
are numbered 1~8 from bottom to top, and columns are numbered 1~8 from left to right.
Input
There will be at most 10000 test cases. Each case contains 6 integers r1, c1, r2, c2, r3, c3 (1<=r1, c1,
r2, c2, r3, c3<=8). Three squares A, B, C are always distinct.
Output
For each test case, print the case number and the minimum number of moves needed.

Sample Input
1 1 8 7 5 6
1 1 3 3 2 2

Output for Sample Input

Case 1: 7
Case 2: 3

``````#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int r3,c3,r1,c1,r2,c2,cas=0,s,a,dx={0,0,1,1,1,-1,-1,-1},dy={1,-1,1,0,-1,1,0,-1};

#define MAX(a,b) ((a)>(b) ? (a):(b))
#define MIN(a,b) ((a)<(b) ? (a):(b))

void search(int x,int y)
{

s=x; s=y; s=0;

{
for(i=0;i<8;i++)
{
if(!a[x][y]&&x>0&&x<=8&&y>0&&y<=8)
{
tail++;
s[tail]=x;
s[tail]=y;
if(a[r2][c2]>0)
{
printf("Case %d: %d\n",++cas,a[r2][c2]);
return;
}
}
}
}
}
int main()
{
while(scanf("%d %d %d %d %d %d",&r1,&c1,&r2,&c2,&r3,&c3)!=EOF)
{
memset(a,0,sizeof(a));
a[r1][c1]=1; a[r3][c3]=1;

search(r1,c1);
}
return 0;
}``````