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),(n,m),(1,1)四个方向

如果可以移动到这四个点中的一个或多个。

输出到其中一个点的最短距离

如果不能输出 Poor Inna and pony!

input

5 7 1 3 2 2

output

2

input

5 5 2 3 1 1

Poor Inna and pony!

PS:开始想成BFS了,一看100万,肯定超时了。

还是思想题,注意:判断边界

 #include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<limits.h>
using namespace std;
int n,m,i,j,a,b; int check(int x,int y)
{
int fx,fy; if(x==i && y==j)
return ;
if(i+a>n&&i-a< || j+b>m&&j-b<)//边界
return INT_MAX;
fx=abs(x-i);
fy=abs(y-j);
if(fx%a!= || fy%b!=)//同为整数步
return INT_MAX;
fx=fx/a;//得到步数
fy=fy/b;//得到步数
int fz;
fz=abs(fx-fy);
if(fz%==)//同奇同偶
{
fz=max(fx,fy);
return fz;
}
else
return INT_MAX;
}
int main()
{
while(~scanf("%d%d%d%d%d%d",&n,&m,&i,&j,&a,&b))
{
int count=INT_MAX;
count=min(check(,),check(,m));
count=min(count,check(n,));
count=min(count,check(n,m));
if(count==INT_MAX)
printf("Poor Inna and pony!\n");
else
printf("%d\n",count);
}
return ;
}

220 DIV2 A. Inna and Pink Pony的更多相关文章

  1. 220 DIV2 B. Inna and Nine

    220 DIV2 B. Inna and Nine input 369727 output 2 input 123456789987654321 output 1 题意:比如例子1:369727--& ...

  2. Codeforces 374A - Inna and Pink Pony

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

  3. codeforces 374A Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行  m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动 ...

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

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

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

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

  6. codeforces round #234B(DIV2) C Inna and Huge Candy Matrix

    #include <iostream> #include <vector> #include <algorithm> #include <utility> ...

  7. codeforces round #234B(DIV2) A Inna and Choose Options

    #include <iostream> #include <string> #include <vector> using namespace std; ; ,,, ...

  8. codeforces round #234B(DIV2) B Inna and New Matrix of Candies

    #include <iostream> #include <vector> #include <string> #include <algorithm> ...

  9. Codeforce Round #220 Div2

    这场气场太大,居然一个题不会! 所以没交! 赛后发现 A:陷阱多- -!不要超过上下界,可以上去再下来! B:不会做! C:自己想太多- -!

随机推荐

  1. 【Qt】Qt之重启应用程序【转】

    简介 今天分享的内容有些意思-如何重启一个应用程序.其实,有时候这是一个很重要的功能点,而且很人性化.易用性很好. 例如:切换用户.当某个用户登录成功之后,需要切换到其它账号,那么这时,你就知道它的重 ...

  2. WPF 绑定五(本身就是数据源)

    xaml: <Window x:Class="WpfApplication1.Window5" xmlns="http://schemas.microsoft.co ...

  3. jQuery ui datepicker 日历转中文

    做个笔记,以后详解 jQuery(function($){ $.datepicker.regional['zh-CN'] = { closeText: '关闭', prevText: '<上月' ...

  4. ASP.NET中的常用快捷键

    想查找ASP.NET中的属性快捷键,忘记了,搜了一下,找到了ASP.NET中的常用快捷键. 大神文章:http://www.cnblogs.com/xiacao/archive/2012/06/12/ ...

  5. 【面试虐菜】—— Apache知识整理

    Apache性能调优1 Apache 部分:1. 移除不用的模块.2. 使用 mod_disk_cache NOT mod_mem_cache .3. 扁平架构配置mod_disk_cache.4.  ...

  6. 菜鸟学习Struts——简易计算器

    这是学习Struts的一个简单的例子文件结构如下: 1.配置Struts环境 2.新建input.jsp,success.jsp,error.jsp input.jsp代码如下: <%@ pag ...

  7. oracle 11g rac 修改字符集

    系统版本: Oracle Linux Server release 5.7 数据库版本: Oracle Database 11g Enterprise Edition Release 11.2.0.3 ...

  8. c++各种排序

    1.插入排序 void InsertSort(int a[], int n) { int temp, i, j; ; i < n; i++) { ]) { temp = a[i]; ; j &g ...

  9. UML 小结(1)- 整体阐述

    前言:              UML( Unified Modeling Language) 又称统一建模语言或标准建模语言,是始于1997年一个OMG标准,它是一个支持模型化和软件系统开发的图形 ...

  10. Cocos2D创建项目

    创建项目 配置好开发环境后, 用CMD切换到~\cocos2d\cocos2d-x-2.2.2\tools\project-creator目录上执行以下脚本 python create_project ...