题目链接:http://codeforces.com/problemset/problem/374/A

题目意思:给出一个 n 行  m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动到四个角落(1,1),(1,m),(n, 1),(n, m) 中的其中一个。假设当前在位置(x, y),规定每次移动遵循,(x+a, y+b) 、 (x+a, y-b)、 (x-a, y+b)、(x-a, y-b)。求最小的移动次数。

求出 (i, j) 到每个角落的距离diff_x, diff_y,而且diff_x 必须要除得尽 a, diff_y除得尽 b,这个很好理解,次数嘛~~~除此,除完之后这两个值必须是同奇或同偶。还有就是移动的时候不能超出边界,在边界时的特判了~~~~

A题都不简单啊~~~

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <limits.h>
using namespace std; int n, m, i, j, a, b; int check(int corner_x, int corner_y)
{
if (corner_x == i && corner_y == j)
return ;
if (i + a > n && i - a < || j + b > m && j - b < ) // 边界处理
return INT_MAX;
int diff_x = abs(corner_x - i);
int diff_y = abs(corner_y - j);
if (diff_x % a || diff_y % b) // 步数要为整数
return INT_MAX;
int div_x = diff_x / a;
int div_y = diff_y / b;
if ((!(div_x&) && div_y&) || (div_x&) && !(div_y&)) // 移动的次数要同时为奇数或偶数
return INT_MAX;
return max(div_x, div_y);
} int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
while (scanf("%d%d%d%d%d%d", &n, &m, &i, &j, &a, &b) != EOF)
{
int ans = INT_MAX;
ans = min(check(,), check(,m));
ans = min(ans, check(n,));
ans = min(ans, check(n,m));
if (ans == INT_MAX)
printf("Poor Inna and pony!\n");
else
printf("%d\n", ans);
}
return ;
}

codeforces 374A Inna and Pink Pony 解题报告的更多相关文章

  1. codeforces 499A.Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/499/A 题目意思:有两种按钮:1.如果当前观看的时间是 t,player 可以自动处理下一分钟,姑且理解 ...

  2. Codeforces 374A - Inna and Pink Pony

    原题地址:http://codeforces.com/contest/374/problem/A 好久没写题目总结了,最近状态十分不好,无论是写程序还是写作业还是精神面貌……NOIP挂了之后总觉得缺乏 ...

  3. 220 DIV2 A. Inna and Pink Pony

    Inna and Pink Pony 输入n,m,i,j,a,b 可以看成n行m列的矩阵,起点(i,j),每次移动(a,b),(-a,-b),(-a,b),(a,-b) 可移动到(1,m),(n,1) ...

  4. cf A. Inna and Pink Pony(思维题)

    题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...

  5. codeforces C1. The Great Julya Calendar 解题报告

    题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...

  6. codeforces B. Eugeny and Play List 解题报告

    题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...

  7. codeforces 433C. Ryouko's Memory Note 解题报告

    题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...

  8. codeforces 556B. Case of Fake Numbers 解题报告

    题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...

  9. codeforces 510B. Fox And Two Dots 解题报告

    题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...

随机推荐

  1. 【ZOJ 1221】Risk

    题 题意 给你20个城市的相邻关系,求给定任意两个城市的最短距离 分析 求任意两个城市最短距离,就是用floyd算法,我脑残忘记了k是写在最外层的. 代码 #include<stdio.h> ...

  2. SqlServer建表规范

    一.数据库在建表时,一般默认字段如下,也算是标准字段吧 删除标志:DeletionStateCode 创建时间:CreateOn 创建人:CreateBy 更新时间:ModifiedOn 更新人:Mo ...

  3. Rootkit Hunter Sourcecode Learning

    目录 . Rootkit Hunter Introduce() . Source Code Frame() . do_system_check_initialisation() . do_system ...

  4. MVC模式的学生信息增删改查

    准备:建一个名为 userdb的数据库.建一个student表,有stuid,stuname,gender三个字段.其中stuid为主键.j加入相应的驱动包,相应的JSTL标签 先看目录结构 代码: ...

  5. 栈的的顺序实例SeqStack实现

    1.#include <stdio.h>#include <stdlib.h>#include "SeqStack.h"/* run this progra ...

  6. 网络html查看器

    1)演示效果:

  7. mq安装参考

    CentOS 6.2 64bit 安装erlang及RabbitMQ Server 1.操作系统环境(CentOS 6.2 64bit) [root@leekwen ~]# cat /etc/issu ...

  8. unity3d下载Obb分包文件

    下载OBB插件包 http://pan.baidu.com/s/1c0ouRZE 1.导入插件 注意事项: 如果项目中已经存在Android 插件,需要merge导入的xml文件例如 AndroidM ...

  9. int(11)最大长度是多少,MySQL中varchar最大长度是多少(转)

    int(11)最大长度是多少,MySQL中varchar最大长度是多少? int(11)最大长度是多少? 在SQL语句中int代表你要创建字段的类型,int代表整型,11代表字段的长度. 这个11代表 ...

  10. 自定义 SqlHelp

    using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Data; usin ...