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的更多相关文章
随机推荐
- Scratch2.0例—接苹果
Scratch2.0例—接苹果 [教学目标] 1. 学习例子,能用和构造条件 ,并把此条件插入到 中:能理解和应用,当条件成立时,不执行积木内的脚本. 2. 对比和 两个积木:前者用于无条件的重复执行 ...
- 毕业论文评审意见、导师意见范文、模板_Smile~风_百度空间
body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...
- Xcode8 去除系统日志输出
Edit Scheme-> Run -> Arguments, 在Environment Variables里边添加 OS_ACTIVITY_MODE = disable
- Nginx 负载均衡 后端服务器获取前端用户真实IP
Nginx 后端 日志文件 获取的都是 前端 负载均衡器的IP 想要获取用户的真实IP 必须 使用Nginx 的模块 http_realip_module 才行!! 1. 编译 Nginx 的时候 ...
- Shell实例----------从文件夹里面多个文件里面查找指定内容
脚本执行方式:脚本名称 目录的路径 要查找的内容 #!/bin/bash num=`ls $1 |tr ' ' '^$'|wc -l` for i in `seq 1 $num` do file_n ...
- Eclipse PHP 代码无法自动提示函数
在 linux 系统的 workwpace 里按 ctrl+h,显示出隐藏的文件,找到 .metadata 文件夹,然后将该文件夹删除,再重启 Eclipse 即可.其实它会将之前 Eclipse 连 ...
- IOS9提示“不受信任的开发者”如何处理
iPhone升级到IOS9版本后,发现部分APP在下载后首次运行时,都会提示“不受信任的应用程序开发者”,这是因为企业证书发布的APP,没有经过AppStore审核,于是iOS对用户做出一个安全性的提 ...
- Apache Mina(二)
在mina的源码,整个框架最核心的几个包是 : org.apache.mina.core.service :IoService.IoProcessor.IoHandler.IoAcceptor.IoC ...
- 单片机modebus RTU通信实现,采用C语言,可适用于单片机,VC,安卓等(转)
源:单片机modebus RTU通信实现,采用C语言,可适用于单片机,VC,安卓等 //modebus_rtu.c /***************************************** ...
- 74HC166与TPIC6A595分析(转)
源:Atmega162串行外设接口SPI 一.Atmega162的SPI接口基本概念与工作原理 SPI接口的全称是"Serial Peripheral Interface",意为串 ...