24h購物| | PChome| 登入
2013-04-23 09:14:31| 人氣472| 回應0 | 上一篇 | 下一篇

[UVA][博弈、記憶化搜索] 12469 - Stones

推薦 0 收藏 0 轉貼0 訂閱站台

Problem I. Stones

Alicia and Roberto like to play games. Today, they are playing a game where there’s a pile of stones on the table. The two players alternate turns removing some stones from the pile. On the first turn, a player can remove any number of stones but he or she must leave at least one stone on the table. On following turns, a player can remove at most twice the number of stones that the other player removed on the previous turn. Each player must always remove at least one stone.

The player that takes the last stone wins.

For example, let’s imagine there’s a pile of 8 stones on the table, and let’s imagine Alicia starts.

  • On the first turn, Alicia must remove a number of stones between 1 and 7 (according to the rules above, on the first turn she can remove any number of stones as long as there remains at least 1). Let’s say Alicia takes 2 stones, leaving 6 on the table.
  • On the second turn, Roberto must remove at least 1 stone and at most 4 stones (because 4 is twice the number of stones that Alicia removed in the previous turn). Let’s say he takes 3, leaving 3 stones on the table.
  • On the third turn, Alicia must remove at least 1 and at most 6 stones (6 is twice the number of stones Roberto took in the previous turn). Since only 3 stones remain on the table, she simply takes the 3 stones and wins the game!

However, Roberto could have played better. If he had taken only 1 stone on the second turn, he would have left 5 on the table with Alicia having to take between 1 and 2 stones. If Alicia took 2, Roberto could win immediately by taking the 3 stones that would remain. So Alicia’s only choice is to take 1 stone, leaving 4 stones and Roberto having to take between 1 and 2 stones. Roberto would then take 1 stone, leaving 3 stones and Alicia having to take between 1 and 2 stones. Roberto could then win after Alicia’s move, regardless of whether she takes 1 or 2 stones. In fact, it turns out that Roberto always has a winning strategy if there are 8 stones and Alicia plays first, even if Alicia plays in the best possible way!

Your task is to determine who wins the game if both players play optimally, assuming Alicia always plays first.

Input

The input contains several test cases.

Each test case contains a single integer n (2 n 1000), the number of stones that are initially on the table.

The last line of the input contains a single 0 and should not be processed.

Output

For each test case, output Alicia or Roberto on a single line, depending on who wins if both players play optimally and Alicia plays on the first turn.

Sample input and output

standard input
standard output


8

2

4

986

987

0

Roberto

Roberto

Alicia

Alicia

Roberto

台長: Morris
人氣(472) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][dp、最長共同回文] 12473 - Common Palindrome
此分類上一篇:[UVA][最長回文路徑、DP] 1244 - Palindromic paths

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文