two positions of a NxN chess board can be connected by pawns move(diagonally) iff both of them are on black/white position, this can be checked by checking the pair. if both of the x,y (start position ) and X,Y(end position) are odd,odd or even,even then they can be connected or both of the pair are of type odd,even then also they are connected, besides for the dissimilarity of the start and end position pairs can not be connected.
If they can be connected then they will need maximum 2 moves.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
#include <iostream> #include <cstdio> #include <cmath> #include <queue> #define ll long long using namespace std; int noOfEven(int a,int b)//either both pair need to be odd,odd and/or even,even ; or odd,even pair both { int cnt=0; if(a%2==0) cnt+=1; if(b%2==0) cnt+=1; return cnt%2; } int main() { ll t,n,curie,N; ll stx,sty,edx,edy; scanf("%lld",&t); while(t--) { scanf("%lld",&curie); scanf("%lld",&N); while(curie--) { scanf("%lld%lld%lld%lld",&stx,&sty,&edx,&edy); if(noOfEven(stx,sty)!=noOfEven(edx,edy)) { printf("no move\n"); continue; } if(stx==edx && sty==edy) { printf("0\n"); continue; } if(abs(stx-edx)==abs(sty-edy)) { printf("1\n"); } else printf("2\n"); }//end while }//end while return 0; } |