Going in Circles
문제
Hercule Poirot, world-renowned detective, was having a lovely cup of tea in his compartment on the Disorient Express when the train conductor rushed in. "We have lost track of the number of train carriages," exclaimed the conductor. You see, this was no ordinary train, and had no first or last train carriage. Instead, the train carriages were connected to form a large cycle, causing the conductor's confusion.
Hercule thought for a moment. "That is most peculiar," he said. "But I may be able to help you." He reached over and grabbed the lamp from the side table. "You see, each train carriage has a light switch like this one. By moving between the carriages and toggling these switches, we can determine the number of train carriages."
The conductor was sceptical, but agreed to try it. "We are in a hurry," he said, "so please determine , the number of carriages that the train consists of, in at most steps." Here a step counts as either moving to an adjacent carriage or toggling a light switch in the current carriage. "The only thing I am certain of is that is at least and at most ."
예제
예제 1
0 1 1 0 1 1 1 1
? right ? right ? right ? flip ? left ? left ? left ! 3