Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

王..后..车..象..都可直接推导..用不着DFS..0MS过..晒晒我的方法..

Posted by zzyzzy12 at 2010-08-04 19:09:57 on Problem 1657 and last updated at 2010-08-04 19:11:17
  车..判断(start.x与end.x)或(start.y与end.y)是否相等..有一对相等则车所需步数为1..否则为2..

  象..判断(start.x+start.y与end.x+end.y)或(|start.x-start.y|与|end.x-end.y|)是否相等..有一对相等则象所需步数为1..
  否则则判断(start.x+start.y+end.x+end.y)的奇偶性..若为偶数..则象所需步数为2..为奇数则象不能到达..

  后..判断车或者象的步数..有一个为1则后所需步数为1..否则所需步数为2..

  王..判断是否车的步数为1..是的话则王的步数为|start.x-start.y+end.x-end.y|..
    否则..判断象的步数是否为1..是的话则王的步数为|start.x-end.x|
    上述都不满足的..则首先将王移到比起点和终点所围成的矩形小的最大的正方形的一角.
    然后再沿斜线走过去..

  o(1)的算法..0Ms..

  本题我交了两次..第一次就是没考虑终点和起点相同的情况..单独判断即可..

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator