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:自己想太多- -!
随机推荐
- linux系统启动流程
BIOS: (Basic Input Output System)基本输入输出系统,一般保存在主板上的BIOS芯片中 BIOS是计算机启动时运行的第一个程序,负责检查硬件并且查找可启动设备. 可启动设 ...
- [大牛翻译系列]Hadoop(15)MapReduce 性能调优:优化MapReduce的用户JAVA代码
6.4.5 优化MapReduce用户JAVA代码 MapReduce执行代码的方式和普通JAVA应用不同.这是由于MapReduce框架为了能够高效地处理海量数据,需要成百万次调用map和reduc ...
- 跨域名设置cookie或获取cookie
可以使用jquery里面的ajax中的jsonp的方式来访问就可以了.代码如下: $.ajax({ url: 'your url', data: {'xx' : 'xx', 'xx2' : 'xx2' ...
- Android的Handler与Activity线程同步
假设这里有同一个Runnable对象r. 可能采用的方法有: 第一种: handler.post(r); 实际上这种方法并没有调用线程someThread的start方法,而是直接调用了Runaabl ...
- selenium for python 所有方法
先列出selenium所有方法,然后挨个使用!说明 add_cookieapplication_cachebackcapabilitiesclosecommand_executorcreate_web ...
- CentOS 6.4 安装搭建 Scrapy 0.22 环境
一.安装Python2.7.6 更新CentOS lib库文件 yum -y update 安装开发工具包 yum groupinstall -y development 安装扩展包 yum inst ...
- linux c 打印彩色字符
#include <stdio.h> #include <string.h> int main(int argc, char **argv) { , j = , str_len ...
- opencv学习笔记(05)——操作相邻区域
下面的例子以灰度图像为例: #include <opencv2\highgui\highgui.hpp> #include <opencv2\imgproc\imgproc.hpp& ...
- Google protobuf安装
1:需要安装sudo apt-get install x11-apps libwayland-ltst-client0 libtxc-dxtn-s2tc0 x11-session-utils x11 ...
- NOIP2015 心得
NOIP2015的复赛已经过去一个多星期了,成绩也已经出来了,作为一个大(ruo)山(sheng)东的蒟蒻,在学了一年之后拿到了255的成绩.这个成绩并不是很好,但也算在我的预料之内. 第一天第一题水 ...