`
20386053
  • 浏览: 461415 次
文章分类
社区版块
存档分类
最新评论

CodeForces 374 A. Inna and Pink Pony

 
阅读更多

一定要考虑全面啊。。。。。

A. Inna and Pink Pony
time limit per test
1 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 ann × mchessboard, a very tasty candy and two numbersaandb.

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 integersn, 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 tonfrom top to bottom and the columns are numbered from 1 tomfrom left to right. Position(i, j)in the statement is a chessboard cell on the intersection of thei-th row and thej-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.

Sample test(s)
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 <cstring>

using namespace std;

const int INF=0x3f3f3f3f;

int abs(int x)
{
    return x<0?-x:x;
}

int px[4],py[4];

int main()
{
    int n,m,x,y,a,b,dx,dy;
    cin>>n>>m>>x>>y>>a>>b;
    px[0]=1;py[0]=1;px[2]=1;py[2]=m;
    px[1]=n;py[1]=1;px[3]=n;py[3]=m;
    int ans=INF;
    for(int i=0;i<4;i++)
    {
        dx=abs(px[i]-x);dy=abs(py[i]-y);
        if(dx&&dy&&dx%a==0&&dy%b==0&&abs(dx/a-dy/b)%2==0) ans=min(ans,max(dx/a,dy/b));
        else if(dx==0&&dy==0) {ans=0; break;}
        else if(dx==0&&n-1>=a&&dy%b==0&&(dy/b)%2==0) ans=min(ans,dy/b);
        else if(dy==0&&m-1>=b&&dx%a==0&&(dx/a)%2==0) ans=min(ans,dx/a);
    }
    if(ans==INF) puts("Poor Inna and pony!");
    else cout<<ans<<endl;
    return 0;
}




分享到:
评论

相关推荐

    Codeforces 988 D. Points and Powers of Two(数学+结论)

    《Codeforces 988 D. Points and Powers of Two》是一道融合了数学与算法的编程竞赛题目。问题的核心在于找到一个数组中的子序列,使得其中任意两个元素之间的差值都是2的幂次。目标是找到这样的子序列,其长度尽...

    Codeforces round 678 D2_Codeforces_源码.zip

    Codeforces 是一个知名的在线编程竞赛平台,吸引了众多程序员参与,以提升编程技能和解决算法问题的能力。"Codeforces round 678 D2" 指的是一场特定的编程比赛,其中"D2"可能代表该轮比赛的难度级别或类别,可能是...

    codeforces算法竞赛.zip

    1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,...

    (源码)基于Python的Codeforces题目集锦.zip

    # 基于Python的Codeforces题目集锦 ## 项目简介 本项目是一个基于Python的Codeforces题目集锦,旨在通过Python脚本来解决Codeforces平台上的各种算法和数据结构问题。项目包含了多个Python脚本,每个脚本对应一个...

    Codeforces 1333C. Eugene and an array(思维) /详解

    Codeforces Round #632 (Div. 2) C. Eugene and an array 题意: 求出一个数列中子区间满足 此区间的任意子区间之和 不为0的区间个数。 思路: 考虑用dp[x]dp[x]dp[x]记录前缀和为xxx的区间右端点。 那么这道题其实...

    CodeForces-Div.2A

    Watermelon: http://codeforces.com/problemset/problem/4/A 2- 71A. Way Too Long Words: http://codeforces.com/problemset/problem/71/A 3- 118A. String Task: http://codeforces.com/problemset/problem/118/A...

    Codeforces 1305 D. Kuroni and the Celebration (交互题)

    题意: 给出 nnn 个点,n−1n-1n−1 条边,最多询问 n2\frac{n}{2}2n​ 次,每次询问 u,vu,vu,v,会给出 uvuvuv的最近公共祖先,求树的根。 ...操作就是一个删除叶子节点的过程。 AC代码: const int N = 1010;...

    Codeforces 1333 F. Kate and imperfection

    题意: 在集合 S=1,2,⋯,nS={1,2,⋯,n}S=1,2,⋯,n 中,对于每个正整数 kkk ,找出一个大小为 kkk 的子集,使得该子集中两两间最大公因数的最大值最小,求这个最小值。 我们考虑如何构造两两间最大公因数的最大值最小...

    CodeForces1230 F. Konrad and Company Evaluation (复杂度分析)

    如果a和b是敌对关系,a的工资比b高,那么a会嘲讽 如果a嘲讽b,b嘲讽c,那么(a,b,c)是一个三元组 问每次操作之后一共有多少对三元组 数据范围:n,m&lt;=1e5,q&lt;=1e5 三元组图例(未修改工资时): 图中三元组...

    Codeforces 1083 A. The Fair Nut and the Best Path(树形DP)

    codeforces每日一练。 题意: 给一棵树,每个点有一个点权,每条边有一个边权,求一条链使得点权和-边权和最大。 思路: 由于我没看清楚题意,以为是求联通子图的点权和-边权和最大,用link-cut-tree写换根,wa10了两...

    zhidd#ZXBlog#Codeforces - 1107B. Digital root & 1107C. Brutality

    Codeforces - 1107B. Digital root & 1107C. Brutality(规律 & 贪心)Codeforces - 1107B.

    Educational Codeforces Round 157D. XOR Construction

    Educational Codeforces Round 157D. XOR Construction

    Codeforces 626 D. Jerry’s Protest(概率DP)

    codeforces每日一练。 题意: 有n张卡片,卡片上的数字就是分数,比如说甲乙两人抽卡,三局两胜,一局得分高的胜,求在甲赢了两局的情况下乙赢了第三局且总分比甲高的概率。 思路: 数据1e3,很明显的On^2算法,所以...

    codeforces.dev:codeforces.dev

    codeforces.dev codeforces.dev 这是应用程序的项目模板。 它位于 。 要使用基于此模板创建一个新项目: npx degit sveltejs/template svelte-app cd svelte-app 请注意,您将需要安装 开始吧 安装依赖项... ...

    Codeforces 1324 F. Maximum White Subtree (树形dp) /详解

    F. Maximum White Subtree time limit per test2 seconds memory limit per test... A tree is a connected undirected graph with n−1 edges. Each vertex v of this tree has a color assigned to it (av=1 if the

    Codeforces 185A - Plant 全测试点49个

    Codeforces 185A - Plant 全测试点49个 Codeforces 是一个在线编程平台,提供了大量的编程题目和比赛。其中,185A - Plant 是一个经典的题目,要求编写一个程序来解决植物生长的问题。 在这个题目中,输入是一个...

    Codeforces比赛用模板.zip

    Codeforces是一个知名的在线编程竞赛平台,它吸引了众多程序员参与,以提升编程技能和解决实际问题的能力。"Codeforces比赛用模板.zip"是一个压缩包,包含了参赛者在Codeforces平台上进行比赛时可能会用到的源码模板...

    Codeforces 721 C. Journey(拓扑排序+DP)

    codeforces每日一练。 题意: 给定n个点,m条有向边,以及k时间。求不超过k时间1-n最多能经过多少个点。 思路: 数据&lt;=5000,说明是个暴力dp。 那么可以用dp[i][j]维护从1到i点经过了j个点,然后初始化为inf,再设...

    简单个人聊天室

    在实现聊天功能时,开发者可能会用到ASP.NET的AJAX(Asynchronous JavaScript and XML)技术,它能实现部分页面刷新,提高用户体验。此外,WebSocket 或 SignalR 可能被用来实现实时通信,这两者都能在客户端和...

    Codeforces 1312 E. Array Shrinking (区间dp)

    E. Array Shrinking time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...Choose a pair of two neighboring equal elements ai=ai+1 (if there is at least o

Global site tag (gtag.js) - Google Analytics