皇后要到任何一格的步數只在0~2之間:
- 0步即是從自己這格走到自己這格。
- 1步即是在自己能夠1次走到的範圍內的格子。
- 2步即是0步、1步無法走到的格子。
C++(0.008)
/*******************************************************/
/* UVa 11494 Queen */
/* Author: Maplewing [at] knightzone.studio */
/* Version: 2012/09/19 */
/*******************************************************/
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int main(){
int start_x, start_y;
int finish_x, finish_y;
while( scanf( "%d%d%d%d", &start_x, &start_y, &finish_x, &finish_y ) != EOF &&
!( start_x == 0 && start_y == 0 && finish_x == 0 && finish_y == 0 )){
if( start_x == finish_x && start_y == finish_y )
printf( "0\n" );
else if( start_x == finish_x || start_y == finish_y ||
abs(finish_x - start_x) == abs(finish_y - start_y) )
printf( "1\n" );
else printf( "2\n" );
}
return 0;
}