Inna and Pink Pony
Input N,m,i,j,a,b
Can be seen as the matrix of n rows M-column, starting point (I,J), each move (a, B), (-a,-b), (-a,b), (A,-b)
Movable to (1,m), (n,1), (N,m), (four) directions
If you can move to one or more of these four points.
The shortest distance from one point to the output
If you cannot output 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: Began to think of BFS, a look at 1 million, must have timed out.
Or a thought problem, note: Judging the boundary
1#include <cstdio>2#include <cmath>3#include <cstdlib>4#include <cstring>5#include <queue>6#include <limits.h>7 using namespacestd;8 intn,m,i,j,a,b;9 Ten intCheckintXinty) One { A intFx,fy; - - if(X==i && y==j) the return 0; - if(i+a>n&&i-a<1|| j+b>m&&j-b<1)//Border - returnInt_max; -Fx=abs (xi); +Fy=abs (yj); - if(fx%a!=0|| fy%b!=0)//same As Integer step + returnInt_max; Afx=fx/a;//get the number of steps atfy=fy/b;//get the number of steps - intFZ; -Fz=abs (fx-fy); - if(fz%2==0)//Same Odd even - { -fz=Max (fx,fy); in returnFZ; - } to Else + returnInt_max; - } the intMain () * { $ while(~SCANF ("%d%d%d%d%d%d",&n,&m,&i,&j,&a,&b))Panax Notoginseng { - intCount=Int_max; theCount=min (Check (1,1), check (1, M)); +Count=min (Count,check (N,1)); ACount=min (Count,check (n,m)); the if(count==Int_max) +printf"Poor Inna and pony!\n"); - Else $printf"%d\n", count); $ } - return 0; -}
View Code
DIV2 A. Inna and Pink Pony