zoukankan      html  css  js  c++  java
  • Codeforces374A

    A. Inna and Pink Pony

    time limit per test1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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.

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 using namespace std;
     5 
     6 int n, m, sx, sy, a, b;
     7 
     8 int main()
     9 {
    10     while(scanf("%d%d%d%d%d%d", &n, &m, &sx, &sy, &a, &b) != EOF)
    11     {
    12         int ans;
    13         if((sx==1&&sy==1)||(sx==1&&sy==m)||(sx==n&&sy==1)||(sx==n&&sy==m))
    14         {
    15             printf("0
    ");
    16         }else if((n-1)<a || (m-1)<b)
    17         printf("Poor Inna and pony!
    ");
    18         else
    19         {
    20             int a1 = (sx-1)/a;
    21             int a2 = (sy-1)/b;
    22             int a3 = (m-sy)/b;
    23             int a4 = (n-sx)/a;
    24             bool fg = false;
    25             if(a1*a==(sx-1) && a2*b==(sy-1))
    26             {
    27                 int tmp = abs(a1-a2);
    28                 if(tmp%2==0)
    29                 {
    30                     ans = max(a1, a2);
    31                     fg = true;
    32                 }
    33             }
    34             if(a1*a==(sx-1) && a3*b==(m-sy))
    35             {
    36                 int tmp = abs(a1-a3);
    37                 if(tmp%2==0 && max(a1, a3) < ans)
    38                 {
    39                     ans = max(a1, a3);
    40                     fg = true;
    41                 }
    42             }
    43             if(a2*b==(sy-1) && a4*a==(n-sx))
    44             {
    45                 int tmp = abs(a4-a2);
    46                 if(tmp%2==0 && max(a4, a2) < ans)
    47                 {
    48                     ans = max(a4, a2);
    49                     fg = true;
    50                 }
    51             }
    52             if(a3*b==(m-sy) && a4*a==(n-sx))
    53             {
    54                 int tmp = abs(a3-a4);
    55                 if(tmp%2==0 && max(a3, a4) < ans)
    56                 {
    57                     ans = max(a3, a4);
    58                     fg = true;
    59                 }
    60             }
    61             if(fg)printf("%d
    ", ans);
    62             else printf("Poor Inna and pony!
    ");
    63         }
    64     }
    65 
    66     return 0;
    67 }
  • 相关阅读:
    ubuntu 下redis的安装简介
    Oracle 的几种循环方式介绍
    NIO 概述 与 通信实例
    io 的一些简单说明及使用
    webSocket的 原理 及 实现
    事务 与事务的 隔离级别 简单说明
    case 函数的简单使用记录下
    java HttpClient 忽略证书的信任的实现 MySSLProtocolSocketFactory
    南京小吃八绝
    JavaScript图表库(百度)
  • 原文地址:https://www.cnblogs.com/Penn000/p/6082139.html
Copyright © 2011-2022 走看看