ZOJ Problem Set - 2276
Lara Croft Tomb Raider is my favourite game. Lara Croft is a brave girl who loves exploration. One time she was be trapped in a place where the only exit was locked.
The lock was special: it was surrounded by a circle of n number, A1,A2,...,An. Initally, there were two sliding square on the number, each time, you can only move either of the two squares around the circle in Ai grid clockwise or anticlockwise. The two square can cross each other. The door is opened when the two squares are in the same position.
Can you help lara escape the dangerous place in the least time, or our poor Lara can't open the door.
The input file contains several test cases.
Each case begins with a natural number n(0<n<=100), then follow n number A1,A2,...,An in clockwise. Then the two squares' position P1,P2 ( 0<=P1<n,0<=P2<n )
The Input is ended by a 0.
If the clock can be opened, you must tell Lara "open it on the nth move!" or "Lara is trapped!"
open it on the 1th move!
Author: ZHOU, Feng
Source: ZOJ Monthly, December 2004