Starting at an unknown vertex of a rectilinear barn, walk the walls to identify the position and reach the exit with the smallest worst-case extra distance.
Hard9Dynamic programmingGame theoryGeometryNo attempts yetTime limit2sMemory limit512 MBFarmer John installed a new milking machine in the barn. It draws so much power that the lights go out from time to time. Bessie has the map of the barn memorized, so she can still reach the exit in the dark, and she wants to know how much extra walking the darkness costs her.
The barn is a simple polygon with N vertices (x1,y1),…,(xN,yN) at integer coordinates, listed in clockwise order. The boundary never touches or crosses itself. The edges alternate between horizontal and vertical, and the first edge can be either one. The exit is at (x1,y1). Bessie stands at (xi,yi) for some i>1, and she knows that she is not standing at the exit.
Bessie walks only along the perimeter. She may turn around at any vertex she reaches, so she can move clockwise or counterclockwise. She knows the map, so she always knows which of the two directions along the wall is the clockwise one.
With the lights on she knows which vertex she is at, so she walks to the exit the short way around, clockwise or counterclockwise, whichever is shorter.
With the lights off she forgets which vertex she is at. She still remembers the map, and she picks up information as she moves.
She walks until the information she has collected leaves exactly one possible starting vertex. From that moment she knows where every step took her, so she walks to the exit the short way around from where she stands. Her distance in the dark is everything she walked while identifying herself, plus that last walk.
Fix one strategy for the dark. For a starting vertex i, let di be the distance that strategy makes her walk and let si be the distance she walks with the lights on. The cost of the strategy is maxi>1(di−si). Find the smallest cost over all strategies.
The first line contains N (4≤N≤200).
Each of the next N lines contains two integers xi and yi, the vertices in clockwise order around the barn. Every coordinate is between −100000 and 100000.
Print one integer, the smallest cost over all strategies for walking in the dark.