CF374A.Inna and Pink Pony

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an n × m chessboard, a very tasty candy and two numbers a and b.

Dima put the chessboard in front of Inna and placed the candy in position (i, j) on the board. The boy said he would give the candy if it reaches one of the corner cells of the board. He's got one more condition. There can only be actions of the following types:

  • move the candy from position (x, y) on the board to position (x - a, y - b);
  • move the candy from position (x, y) on the board to position (x + a, y - b);
  • move the candy from position (x, y) on the board to position (x - a, y + b);
  • move the candy from position (x, y) on the board to position (x + a, y + b).

Naturally, Dima doesn't allow to move the candy beyond the chessboard borders.

Inna and the pony started shifting the candy around the board. They wonder what is the minimum number of allowed actions that they need to perform to move the candy from the initial position (i, j) to one of the chessboard corners. Help them cope with the task!

迪马和英娜玩得非常开心!此时,英娜正坐在魔法草坪上,和一只粉红色的小马玩耍。迪马也想一起玩,于是他带来了一个 n×mn \times m 的国际象棋棋盘、一颗非常美味的糖果,以及两个数 aa 和 bb。

迪马把棋盘摆在英娜面前,并将糖果放在棋盘上的位置 (i, j)(i,\,j)。他告诉英娜:如果糖果能到达棋盘的任意一个角格(corner cell),他就把糖果送给她。但他还有一个附加条件:糖果的移动仅允许以下四种类型之一:

  • 将糖果从棋盘上的位置 (x, y)(x,\,y) 移动到 (x−a, y−b)(x - a,\,y - b);
  • 将糖果从棋盘上的位置 (x, y)(x,\,y) 移动到 (x+a, y−b)(x + a,\,y - b);
  • 将糖果从棋盘上的位置 (x, y)(x,\,y) 移动到 (x−a, y+b)(x - a,\,y + b);
  • 将糖果从棋盘上的位置 (x, y)(x,\,y) 移动到 (x+a, y+b)(x + a,\,y + b)。

当然,迪马不允许糖果移出棋盘边界。

英娜和小马开始在棋盘上移动这颗糖果。他们很好奇:从初始位置 (i, j)(i,\,j) 出发,最少需要多少次上述允许的操作,才能使糖果到达棋盘的任意一个角格?请帮助他们解决这个问题!

输入格式

The first line of the input contains six integers n, m, i, j, a, b (1 ≤ n, m ≤ 106; 1 ≤ i ≤ n; 1 ≤ j ≤ m; 1 ≤ a, b ≤ 106).

You can assume that the chessboard rows are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. Position (i, j) in the statement is a chessboard cell on the intersection of the i-th row and the j-th column. You can consider that the corners are: (1, m), (n, 1), (n, m), (1, 1).

输入的第一行包含六个整数 nn、mm、ii、jj、aa、bb(其中 1≤n,m≤1061 \leq n, m \leq 10^6;1≤i≤n1 \leq i \leq n;1≤j≤m1 \leq j \leq m;1≤a,b≤1061 \leq a, b \leq 10^6)。

可以假设棋盘的行从上到下编号为 11 到 nn,列从左到右编号为 11 到 mm。题目中提到的位置 (i,j)(i, j) 表示棋盘上第 ii 行与第 jj 列相交的格子。可认为四个角分别为:(1,m)(1, m)、(n,1)(n, 1)、(n,m)(n, m)、(1,1)(1, 1)。

输出格式

In a single line print a single integer — the minimum number of moves needed to get the candy.

If Inna and the pony cannot get the candy playing by Dima's rules, print on a single line "Poor Inna and pony!" without the quotes.

在一行中输出一个整数——获取糖果所需的最少移动次数。

如果按照迪马的规则,因娜和小马无法获得糖果,则在一行中输出“Poor Inna and pony!”(不含引号)。

输入输出样例

  • 输入#1

    5 7 1 3 2 2

    输出#1

    2
  • 输入#2

    5 5 2 3 1 1

    输出#2

    Poor Inna and pony!

说明/提示

Note to sample 1:

Inna and the pony can move the candy to position (1 + 2, 3 + 2) = (3, 5), from there they can move it to positions (3 - 2, 5 + 2) = (1, 7) and (3 + 2, 5 + 2) = (5, 7). These positions correspond to the corner squares of the chess board. Thus, the answer to the test sample equals two.

样例 1 说明:

因娜和小马可以将糖果移动到位置 (1 + 2, 3 + 2) = (3, 5)(1 + 2, 3 + 2) = (3, 5);从该位置出发,他们可进一步将其移动至 (3 − 2, 5 + 2) = (1, 7)(3 - 2, 5 + 2) = (1, 7) 和 (3 + 2, 5 + 2) = (5, 7)(3 + 2, 5 + 2) = (5, 7)。这些位置对应棋盘的四个角格之一。因此,该测试样例的答案为 22。

输入解题思路,AI测评打分。不知道怎么写?

首页