编程介的小学生 2016-11-27 13:09 采纳率: 20.5%
浏览 972
已采纳

A flea on a chessboard

Description
POJ 1728 A flea on a chessboard [number theory - loop modulo circuit judge issues +]
Security 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 <= 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 milimiters 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条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题