Description
Input
The input contains no more than 10000 sets of data. Each set of data contains 6 integers r1, C1, R2, C2, R3, C3 (1<=r1, C1, R2, C2, R3, c3<=8). Three lattice A, B, C are guaranteed to be different.
Output
For each set of data, the test point number and the minimum number of steps are output.
Sample Input
<span class= "Sampledata" >1 1 8 7 5 (1 3 3 2 2</span>
Sample Output
<span class= "Sampledata" >case 1:7case 2:3</span>
<span class= "Sampledata" ></span><pre name= "code" class= "HTML" > #include <iostream> #include <cstdio> #include <cstring> #include <queue>using namespace Std;int di,dj,r,c;int m[9][9];struct node {int i,j,time;}; Queue<node>qq;int x[8]={0,1,1,1,0,-1,-1,-1},y[8]={1,1,0,-1,-1,-1,0,1};void BFs () {while (!qq.empty ()) {node Temp=qq.front (); node T=temp;qq.pop (); if (t.i==r&&t.j==c) break;for (int i=0;i<8;i++) {t=temp;t.i+=x[i]; T.j+=y[i];t.time+=1;if (t.i<1 | | t.i>8 | | t.j<1 | | t.j>8) continue;if (t.i==r && t.j==c) continue;if (T.TIME<M[T.I][T.J]) {M[t.i][t.j]=t.time;qq.push (t);}}} int main () {int Si,sj,i,j,sigh;sigh=0;while (cin>>si>>sj>>di>>dj>>r>>c) {for (i= 1;i<9;i++) {for (j=1;j<9;j++) m[i][j]=10000;} M[si][sj]=0;while (!qq.empty ()) Qq.pop (), node Temp={si,sj,0};qq.push (temp), BFS ();p rintf ("Case%d:%d\n", ++sigh,m[di ][DJ]);}}
<span class= "Sampledata" ></span>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
CSU's mutilated chessboard (BFS)