若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1166: A flea on a chessboard

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,040

题目描述

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 <= 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.

输入

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. For test case print one line of output in the format shown in the sample.

输出

freeproblemset

样例输入

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

样例输出

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).

参考代码

暂无

解析

暂无

hustoj

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

Dreams孤独患者 Skip 原站点
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist