Link: 10620-A Flea on a Chessboard
On a chess board, the coordinate system is established with the lower left corner as the coordinate axis, and the lattice in the lower left corner is black. The length of each lattice side is s. Assuming that the board is infinitely large, given the starting position and direction of the flea, ask whether the hard-pressed flea can jump to the white grid.
Solution: enumerate the first two steps of s *, because the 2*2 lattice forms the minimum unit of 2 white and two black, and the side length is 2 * s, the 2 * s step is equal to the jump back to the corresponding starting position.
# Include
# Include
Int s, x, y, dx, dy; bool judge (int a, int B) {return (a % s) & (B % s) & (a/s + B/s) % 2);} int main () {while (scanf ("% d ", & s, & x, & y, & dx, & dy) = 5 & s + x + y + dx + dy) {int I; for (I = 0; I <2 * s; I ++) {if (judge (x, y) {printf ("After % d jumps the flea lands at (% d, % d ). \ n ", I, x, y); break;} x + = dx; y + = dy;} if (I = 2 * s) printf ("The flea cannot escape from black squares. \ n ") ;}return 0 ;}