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:自己想太多- -!
随机推荐
- 添加远程链接MySQL的权限
mysql> grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’; 权限1,权限2,…权限n代表select,ins ...
- !!! FAILED BINDER TRANSACTION !!! TransactionTooLargeException
- ::): !!! FAILED BINDER TRANSACTION !!! xxxRecorder 运行40多分钟,崩溃,捕获日志 03-12 14:50:12.353: E/JavaBinde ...
- 【转】MyEclipse快捷键大全(绝对全)
ref:http://www.douban.com/note/254195820/?type=like# ctrl+w 关闭单个窗口 F3 跳转到类.变量的声明 F11 运行上次程序 Ctrl + F ...
- Geoserver 相关学习
参考资料: http://geoserver.org/ http://docs.geoserver.org/ 相关文档 http://docs.geoserver.org/stable/en/user ...
- mslookup
Microsoft Windows [版本 6.1.7601]版权所有 (c) 2009 Microsoft Corporation.保留所有权利. C:\Users\Administrator> ...
- How to add EDT relation table[AX2012]
setp 1. First create New Edit. setp 2.Create New Table First Table Name is NParentRel then drag and ...
- Resource temporarily unavailable
数据库版本:5.5.14 操作系统版本:contos 6.3 服务器256G内存,安装90个实例.通过脚本启动90个mysql数据库实例,会有几个实例无法启动,进程启动后直接被杀死.查看mysql日志 ...
- awk中文手册
1. 前言 有关本手册 : 这是一本awk学习指引, 其重点着重于 : l awk 适于解决哪些问题 ? l awk 常见的解题模式为何 ? 为使读者快速掌握awk解题的模 ...
- Linux /dev 自动创建设备节点
#include <linux/module.h> #include <linux/module.h> #include <linux/kernel.h> #inc ...
- fawef
欢迎使用马克飞象 @(示例笔记本)[马克飞象|帮助|Markdown] 马克飞象是一款专为印象笔记(Evernote)打造的Markdown编辑器,通过精心的设计与技术实现,配合印象笔记强大的存储和同 ...