2 shunfurh shunfurh 于 2017.09.07 11:54 提问

A Flea on a Chessboard

An infinite chessboard is obtained by extending a finite chessboard to the right and up infinitely. Each square of the chessboard is either black or white with the side of S milimeters, 0 < S <= 1000. The leftmost bottom square of the chessboard is black. A flea is positioned on the chessboard at the point (x, y) (given in milimeters) and makes jumps by jumping dx milimeters to the right and dy milimeters up, 0 < dx, dy, that is, a flea at position (x, y) after one jump lands at position (x+dx, y+dy).

Given the starting position of the flea on the board your task is to find out after how many jumps the flea will reach a white square. If the flea lands on a boundary between two squares then it does not count as landing on the white square. Note that it is possible that the flea never reaches a white square.

Input

Each test case consists of one line of input containing five non-negative numbers separated by white space and giving integers S, x, y, dx, and dy. An input line containing five zeroes follows the last test case.

Output

For test case print one line of output in the format shown in the sample.

Sample Input

10 2 3 3 2
100 49 73 214 38
25 0 0 5 25
407 1270 1323 1 1
18 72 6 18 6
407 1270 1170 100 114
0 0 0 0 0

Sample Output

After 3 jumps the flea lands at (11, 9).
After 1 jumps the flea lands at (263, 111).
The flea cannot escape from black squares.
After 306 jumps the flea lands at (1576, 1629).
The flea cannot escape from black squares.
After 0 jumps the flea lands at (1270, 1170).

1个回答

caozhy
caozhy   Ds   Rxr 2017.09.22 08:34
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
POJ1728 A flea on a chessboard
首先很容易判断出当前坐标(x, y)落在白格子上的条件是q(x / S) + q(y / S) 为奇数, q表示下取整 那么可以从起点不断地循环跳,并用上述条件判断是否跳到了白格子, 如果不在白格子,则对当前当前 坐标模S,当(x % S, y % S)已经被访问过时说明无解 这里有一个要注意的地方,那就是: 模运算时如果x % 2 == 0(或者y % 2 == 0)时即落在边界上,需要判断这个
POJ 1728 A flea on a chessboard
A flea on a chessboardTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 1509 Accepted: 491DescriptionAn infinite chessboard is obtained by extending a finit
UVA 10620 - A Flea on a Chessboard(鸽笼原理)
UVA 10620 - A Flea on a Chessboard 题目链接 题意:给定一个跳蚤位置和移动方向,现在在一个国际象棋棋盘上,左下角为黑格,一个格子为s*s,判断能否移动到白格子,问要移动多少次才能到白格,边界不算白格。 思路:利用鸽笼原理落在黑格子和边界上的一共有(s + 1)^2个点,也就是说,如果形成循环,周期肯定在这之内,所以可以不断去模拟跳格子,直到踩到白
UVa10620 - A Flea on a Chessboard(模拟问题)
An infinite chessboard is obtained by extending a finite chessboard to the right and up infinitely. Each square of the chessboard is either black or white with the side of S milimiters, 0 S x, y)
hdu 1564 Play a game (博弈 奇偶规律)
Play a gameTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2322 Accepted Submission(s): 1865Problem Description New Year is Coming! ailyan
Sicily 2683. Alice and Bob
ConstraintsTime Limit: 1 secs, Memory Limit: 256 MBDescriptionBob is very famous because he likes to play games. Today he puts a chessboard in the desktop, and plays a game with Alice. The size of the
HDU 1564 Play a game(巴什博弈)
题意:给定一个n*n的表格,在一个角上放入一块石头,然后两个人轮流移动石头,只能水平和竖直移动石子,而且不能移到已经访问的格子,最后没法移动的玩家为输者。现在输入任意的n输出谁输谁胜。这个随便画两个就能很容易的推算出胜负。 太简单的水题。
Codeforces 961C Chessboard(将碎了的、染色乱了的棋盘碎片拼一起)
题目链接:点击打开链接Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4pieces, each of size n by n, n is always odd. And what's...
【CodeForces】445A - DZY Loves Chessboard(dfs)
题目链接:点击打开链接 A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY loves chessboar
1016: Roliygu and Yilan
题目描述: Roliygu is famous because he likes to play games. Today he puts a chessboard in the desktop,and plays a game with Yilan. The size of the chessboard is n by n. A stone is placed in a corne