Two sheepdogs block two neighboring cells each turn to steer a randomly moving sheep home and minimize its expected number of moves there.
Hard9ProbabilityGame theoryMathNo attempts yetTime limit20sMemory limit1024 MBBleatrix the sheep lives on an infinite grid of unit cells. Her home is the cell (0,0), and every coordinate is given relative to that cell. Bleatrix sleepwalks, so right now she is in the cell (X,Y), which is X columns east of and Y rows north of her home. The two sheepdogs assigned to protect her have just noticed that she is missing, and they want to herd her back home.
Before each of Bleatrix's moves, the two sheepdogs move to any cells they want. They may not both move to the same cell, and neither may move to the cell Bleatrix is standing on. Once the sheepdogs are in place, Bleatrix takes the four unit moves (north, south, west, east), discards the ones that would take her into a cell with a sheepdog, and chooses uniformly at random among the moves that remain. Then the sheepdogs position themselves again, and so on. Unlike Bleatrix, the sheepdogs do not have to make unit moves.
Once Bleatrix reaches her home at (0,0) she wakes up and grazes, and she makes no further moves.
The sheepdogs coordinate to minimize the expected number of moves Bleatrix makes before she reaches home. Compute that expected number.
The first line contains the number of test cases T. Each of the next T lines contains two integers X and Y, the coordinates of the cell Bleatrix is sleepwalking in.
For each test case, print one line in the form Case #x: y, where x is the test case number starting from 1, and y is the expected number of Bleatrix's moves written with exactly six digits after the decimal point. The exact answer never falls on a rounding boundary at the sixth decimal digit, so the value you print is uniquely determined.
X and Y may be negative. An X of −1 means the cell is one unit west of Bleatrix's home cell, and a negative Y means the cell is south of her home cell.
Consider X=−1 and Y=1, so Bleatrix starts one cell west of and one cell north of her home. Before her first move, the two sheepdogs can position themselves in the cells (−2,1) and (−1,2). Whichever direction she then chooses, she ends up one step away from home. That still does not guarantee that she goes home on her next move, because the sheepdogs can block only two cells and Bleatrix picks at random between the two that are left. The remaining details are left for you to discover.