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),(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的更多相关文章
- 220 DIV2 B. Inna and Nine
220 DIV2 B. Inna and Nine input 369727 output 2 input 123456789987654321 output 1 题意:比如例子1:369727--& ...
- Codeforces 374A - Inna and Pink Pony
原题地址:http://codeforces.com/contest/374/problem/A 好久没写题目总结了,最近状态十分不好,无论是写程序还是写作业还是精神面貌……NOIP挂了之后总觉得缺乏 ...
- codeforces 374A Inna and Pink Pony 解题报告
题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行 m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动 ...
- cf A. Inna and Pink Pony(思维题)
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...
- codeforces 499A.Inna and Pink Pony 解题报告
题目链接:http://codeforces.com/problemset/problem/499/A 题目意思:有两种按钮:1.如果当前观看的时间是 t,player 可以自动处理下一分钟,姑且理解 ...
- codeforces round #234B(DIV2) C Inna and Huge Candy Matrix
#include <iostream> #include <vector> #include <algorithm> #include <utility> ...
- codeforces round #234B(DIV2) A Inna and Choose Options
#include <iostream> #include <string> #include <vector> using namespace std; ; ,,, ...
- codeforces round #234B(DIV2) B Inna and New Matrix of Candies
#include <iostream> #include <vector> #include <string> #include <algorithm> ...
- Codeforce Round #220 Div2
这场气场太大,居然一个题不会! 所以没交! 赛后发现 A:陷阱多- -!不要超过上下界,可以上去再下来! B:不会做! C:自己想太多- -!
随机推荐
- 在指定的DSN中,驱动程序和应用程序之间的体系结构不匹配
今天在使用plsql通过odbc导入excel数据时发生了一个错误,截图如下: 错误提示为:驱动程序和应用程序之间的体系结构不匹配. 后来百度了一下,得出答案.系统是win10 64位.excel驱动 ...
- 简单的同步MSMQ
# 简单的同步MSMQ ```cs using System; using System.Messaging; using System.Windows.Forms; namespace MSMQEx ...
- Android开发之计算器(一)界面设计之activity_main布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- Use Sandcastle Help File Builder to generate help document
http://shfb.codeplex.com/ Note: If the the help file contains the text "[Missing <param> ...
- vs2010中的反编译
有这样的需求,一个.dll文件,如何查看里面的代码呢?网上有很多关于反编译的运用的. http://blog.csdn.net/lyflcear/article/details/8102057 昨天( ...
- Python解析HTML的开发库pyquery
PyQuery是一个类似于jQuery的Python库,也可以说是jQuery在Python上的实现,能够以 jQuery 的语法来操作解析 HTML 文档,易用性和解析速度都很好. 例如,一段豆瓣h ...
- 【BZOJ 1006】[HNOI2008]神奇的国度
Description K国是一个热衷三角形的国度,连人的交往也只喜欢三角原则.他们认为三角关系:即AB相互认识,BC相互认识,CA相互认识,是简洁高效的.为了巩固三角关系,K国禁止四边关系,五边关系 ...
- Hello BaiduMap
百度提供了地图的API,可以在android手机上用,这里其实只要参考百度给的文档就好了.因为api不断在更新,所以网上的博客感觉还是不太好,直接看官网的文档比较靠谱 这里照着百度文档上面提供的文档我 ...
- ORACLE 变量定义
DECLARE v_productid productinfo.productid%TYPE; v_productname ); v_productprice ,); v_quantity ); v_ ...
- iOS刷新第三方MJRefresh的基本使用
iOS开发中最好用的刷新第三方框架 MJRefresh GitHub : https://github.com/CoderMJLee/MJRefresh UIRefreshControl的介绍 1,U ...