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. VIM中的寄存器简介

    原来在vim粘贴从其他地方复制过来的文本的时候,一直用的shift + inert,那时就想,能不能够直接就像p那样粘贴,不必非得进入插入模式再来粘贴.后来看了<vim实用技巧>上关于vi ...

  2. javascript中的光标

    最近项目中要做一个键盘操作,光标移动的功能:增强用户体验:问朋友查资料了解到这方面的知识:整理备忘: 1.IE使用textRange对象,其他使用selectionStart selectionEnd ...

  3. 杂项一之js,<select>标签

    一.在aspx页面中实现 修改与删除页面的跳转 前台js部分: 在上部的js部分中写,根据传过来的id,来经行页面的跳转,并把id传过去 js部分就是实现了一个页面跳转的功能 (还有确认框confir ...

  4. Nginx 之并发优化

    客户端/服务端 连接数 ulimit -n 100000 nginx 链接数 10240 个 worker_connections 10240;允许打开文件数worker_processes 1;wo ...

  5. Crusher Django 学习笔记4 使用Model

    http://crusher-milling.blogspot.com/2013/09/crusher-django-tutorial4-using-basic.html 顺便学习一下FQ Crush ...

  6. java web 路径 --转载

    主题:java(Web)中相对路径,绝对路径问题总结 1.基本概念的理解 绝对路径:绝对路径就是你的主页上的文件或目录在硬盘上真正的路径,(URL和物理路径)例如:C:\xyz\test.txt 代表 ...

  7. CLR via C# 内存管理读书记

    1. CLR 垃圾回收采用基于代的机制, 在一次垃圾回收中存活下来的对象被提升到另一代 2. 在确认对象是否垃圾时,从一组根开始,根包括静态字段,方法参数,局部变量等 3. 使用CriticalFin ...

  8. Jquery 在动态元素上绑定事件

    弄了很久却没有弄出来,感觉没有错,但是动态元素上的事件根本就不响应,代码如下: <input type="button" id="btnyes" valu ...

  9. js数组的splice方法

    w3school文章链接:http://www.w3school.com.cn/jsref/jsref_splice.asp splice:拼接,结合. splice()方法向数组添加/删除元素,返回 ...

  10. 深入理解ThreadLocal(二)

    3 InheritableThreadLocal的使用 通过上面的分析知道通过ThreadLocal保存的值是线程隔离的.其实在Thread对象中,还有一个ThreadLocal.ThreadLoca ...