编程介的小学生 2017-08-20 11:52 采纳率: 20.5%
浏览 688
已采纳

Chemfrog's Fairy Tale

Because of the evil wizard's curse, Chemfrog became a frog. Luckily, he met Cyjj. She told him that he could become a handsome boy again if he found the pretty princess and got her kiss. But the princess was captured by the evil wizard, and she was enjailed in the XiaoYingzhou in the West Lake.

Chemfrog bought a West Lake map. He found that the West Lake was in a regular shape as the picture1 shown below. So he marked the center of the lake to be (0, 0), and the northmost point to be (0, N), the southmost point to be (0, -N), the eastmost point to be (N, 0), the westmost point to be (-N, 0). Then he could marked the position of XiaoYingzhou with P(px, py).

picture 1: suppose N is 5

Time and tide wait for no one. Chemfrog jumped into the West Lake immediately, and went forward to P. When he arrived at the position (x0, y0), he felt something strange: he could not move freely! That's because the evil wizard detected his action and bewitched the West Lake. Chemfrog realized the problem soon, and he also found the jumping rule to fight against the bewitchery:

Rule 1: jumping like the Knight in Chess.
Rule 2: jumping without falling back.
Rule 3: jumping within the West Lake.

Picture 2 and Picture 3 show the Rules:

picture 2

picture 3

Note: if chemfrog jumped to the point marked blue from the yellow point, the next jump he could choose 5 point marked green, but the black ones and the yellow one were forbidden.

So Chemfrog jumped to (x1, y1) from (x0, y0). The evil wizard would not await his doom, and he flew to the West Lake to prevent Chemfrog to meet the princess. It's supposed that Chemfrog must jump onto the XiaoYingzhou within M jumps.

Is it possible for Chemfrog to meet the princess? Now it's turn for you to calculate whether Chemfrog could meet the pretty girl successfully. If it is possible, output the minimum number of jumping.

Input:

The input will consist of several test cases. The first line of each test case is two nonnegative number, said N (2<=N<=500) and M (0<M<=500). The second line contains six integer numbers: x0, y0, x1, y1, px, py. You may know that (x0, y0), (x1, y1), (px, py) are in the West Lake, and (x0, y0) won't equal to (px, py). N=M=0 signals the end of input file.

Output:

For each case, if Chemfrog could get to the XiaoYingzhou within M jumps, output the minimun number of jumping, otherwise output -1.

Sample Input:
7 5
1 2 2 4 0 0
7 3
1 2 2 4 0 0
2 10
-1 -1 0 1 0 0
0 0

Sample Output:
5
-1
-1

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-09-01 15:54
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值