Codeforces Round #220 (Div. 2) A题
来源:互联网 发布:如何查询软件著作权 编辑:程序博客网 时间:2024/06/07 16:21
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!
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).
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.
5 7 1 3 2 2
2
5 5 2 3 1 1
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.
Ps:
这个。。。第一次参加CF比赛,就被HACK了。。。这个题被HACK是因为没有考虑到在运行过程中超过界限的情况。
最终AC代码如下:
#include <stdio.h>#include <math.h>int main(){ int m, n, i, j, a, b, x, y; scanf("%d%d", &m, &n); scanf("%d%d%d%d", &i, &j, &a, &b); if((i==1&&j==1)||(i==1&&j==n)||(i==m&&j==1)||(i==m&&j==n)) printf("0\n"); else { if((a+i>m&&i-a<=0)||(b+j>n&&j-b<=0)) puts("Poor Inna and pony!"); else { if((((i-1)%a!=0&&(m-i)%a!=0))||((j-1)%b!=0&&(n-j)%b!=0)) printf("Poor Inna and pony!\n"); else { y = 1000000; x = 1000000; if((i-1)%a==0&&(j-1)%b==0) { if((abs((i-1)/a-(j-1)/b))%2==0) { if((i-1)/a>(j-1)/b) x = (i-1)/a; else x = (j-1)/b; } if(y > x) y = x; } x = 1000000; if((i-1)%a==0&&(n-j)%b==0) { if((abs((i-1)/a-(n-j)/b))%2==0) { if((i-1)/a>(n-j)/b) x = (i-1)/a; else x = (n-j)/b; } if(y > x) y = x; } x = 1000000; if((m-i)%a==0&&(j-1)%b==0) { if((abs((m-i)/a-(j-1)/b))%2==0) { if((m-i)/a>(j-1)/b) x = (m-i)/a; else x = (j-1)/b; } if(y > x) y = x; } x = 1000000; if((m-i)%a==0&&(n-j)%b==0) { if((abs((m-i)/a-(n-j)/b))%2==0) { if((m-i)/a>(n-j)/b) x = (m-i)/a; else x = (n-j)/b; } if(y > x) y = x; } if(y == 1000000) printf("Poor Inna and pony!\n"); else printf("%d\n", y); } } } return 0;}
- Codeforces Round #220 (Div. 2) A题
- Codeforces Round #220 (Div. 2)A-C
- Codeforces Round #181 (Div. 2) A题
- Codeforces Round #184 (Div. 2) A题
- Codeforces Round #172 (Div. 2) A题
- Codeforces Round #166 (Div. 2) A题
- Codeforces Round #132 (Div. 2) A题
- Codeforces Round #131 (Div. 2) A题
- Codeforces Round #133 (Div. 2) A题
- Codeforces Round #137 (Div. 2) A题
- Codeforces Round #138 (Div. 2) A题
- Codeforces Round #147 (Div. 2) A题
- Codeforces Round #141 (Div. 2) A题
- Codeforces Round #143 (Div. 2) A题
- Codeforces Round #135 (Div. 2) A题
- Codeforces Round #163 (Div. 2) A题
- Codeforces Round #146 (Div. 2) A题
- Codeforces Round #111 (Div. 2) A题
- c/c++ 调用api操作mysql
- 大数据能做什么
- 主存储器空间的分配和回收代码
- 对字符串按照从小到大的顺序进行排序
- jdk环境变量的配置和android环境变量及adb的配置
- Codeforces Round #220 (Div. 2) A题
- 如何才能使用apt-get使用本地安装源进行安装
- Shell编程基础
- effective c++ note1
- 神经网络设计_学习规则总结
- poj3134Power Calculus(IDA*)
- 字符编码笔记:ASCII,Unicode和UTF-8
- 百钱买百鸡
- IntelliJ IDEA java工程如何添加jar