Codeforces374A
A. Inna and Pink Pony
256 megabytes
standard input
standard output
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!
Input
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).
Output
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.
Examples
input
5 7 1 3 2 2
output
2
input
5 5 2 3 1 1
output
Poor Inna and pony!
Note
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.
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std; int n, m, sx, sy, a, b; int main()
{
while(scanf("%d%d%d%d%d%d", &n, &m, &sx, &sy, &a, &b) != EOF)
{
int ans;
if((sx==&&sy==)||(sx==&&sy==m)||(sx==n&&sy==)||(sx==n&&sy==m))
{
printf("0\n");
}else if((n-)<a || (m-)<b)
printf("Poor Inna and pony!\n");
else
{
int a1 = (sx-)/a;
int a2 = (sy-)/b;
int a3 = (m-sy)/b;
int a4 = (n-sx)/a;
bool fg = false;
if(a1*a==(sx-) && a2*b==(sy-))
{
int tmp = abs(a1-a2);
if(tmp%==)
{
ans = max(a1, a2);
fg = true;
}
}
if(a1*a==(sx-) && a3*b==(m-sy))
{
int tmp = abs(a1-a3);
if(tmp%== && max(a1, a3) < ans)
{
ans = max(a1, a3);
fg = true;
}
}
if(a2*b==(sy-) && a4*a==(n-sx))
{
int tmp = abs(a4-a2);
if(tmp%== && max(a4, a2) < ans)
{
ans = max(a4, a2);
fg = true;
}
}
if(a3*b==(m-sy) && a4*a==(n-sx))
{
int tmp = abs(a3-a4);
if(tmp%== && max(a3, a4) < ans)
{
ans = max(a3, a4);
fg = true;
}
}
if(fg)printf("%d\n", ans);
else printf("Poor Inna and pony!\n");
}
} return ;
}
Codeforces374A的更多相关文章
随机推荐
- CentOS tengine mysql 5.7 php 5.6
CentOS 7.x 编译安装 LNMP L 版本是 CentOS 7.x x64版本, N 我们使用tengine 的最新版本,主要原因是因为tengine 默认支持很多的模块. M 这里我们选用 ...
- head和tail命令-----得到头尾N行或者这去掉尾头N/N-1行
[algo@localhost tmp]$ cat test 1 2 3 4 5 head得到头部2行,删掉尾部2行 [algo@localhost tmp]$ head -n +2 test 1 ...
- flex中Event类的使用
当您创建自己的自定义 Event 类时,必须覆盖继承的 Event.clone() 方法,以复制自定义类的属性.如果您未设置在事件子类中添加的所有属性,则当侦听器处理重新分派的事件时,这些属性将不会有 ...
- iBATIS的多对多 数据库设计及实现
iBATIS的多对多映射配置方法和多对一映射配置方法差不多,不同的是,多对多映射,数据库设计上需要一个记录两个类关系的中间表,本文以学生-老师为例,在iBATIS的sqlmap中配置多对多关系. iB ...
- UIImage创建图片的两种方式的区别
在工作中经常会遇到添加图片,用哪种方式添加更好呢?请看详解 方法一: UIImage *image = [UIImage imageNamed:@"haha"]; 这种方法创建的图 ...
- CentOS 6.5 GIT 服务器搭建
环境: Git Sserver IP: 10.6.0.2 Git Client IP: 10.6.0.126 1. 在 Git Server 安装软件所需的依赖包 yum install curl-d ...
- mac系统不能使用127.0.0.2的解决方案
英语学得不好,国外这位大神的精彩解释不是特能看的懂.我模仿的试了一下. 解决方案: 1.打开mac终端 2.输入:sudo ifconfig lo0 alias 127.1.1.1 netmask 0 ...
- LPC1788的内部EEPROM使用
Lpc1788内置有eeprom 使用代码 #ifndef __E2PRONINCHIP_H_ #define __E2PROMINCHIP_H #include "common.h&quo ...
- github上forck一个分支之后,如何和主分支同步
github forck一个分之后,如果过一段时间就会和主分支的差异比较大. 这样提交pr的时候 就会冲突,这个时候我们就需要和主分支同步代码 git remote add upstream git@ ...
- stm32实现待机唤醒
STM32的低功耗模式有3种:1.睡眠模式(CM3内核停止,外设仍然运行)2.停机模式(所有时钟都停止)3.待机模式(1.8v内核电源关闭) 进入待机模式的方法,以及设置WK_UP引脚用于把STM32 ...