Ultraviolet A 10620-a Flea on A Chessboard (violent + mathematical)

Source: Internet
Author: User

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 ;}

   

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.