#P8658. [蓝桥杯 2017 国 A] 填字母游戏

[蓝桥杯 2017 国 A] 填字母游戏

Description

Xiaoming often plays the game LOL and is addicted to it. One time he wanted to challenge Master K, but Master K said:

“Let’s first play a game of filling letters into blanks. If you can’t beat me, then don’t play LOL anymore.”

Master K draws a row of nn cells on paper, and asks Xiaoming and him to take turns filling letters into them.

Rules:

  1. When it is someone’s turn, they can only fill L or O into one empty cell.

  2. Whoever first makes the letters form the string LOL wins.

  3. If all cells are filled and LOL still cannot be formed, then it is a draw.

Xiaoming tried several times and lost every time. He feels ashamed and hopes you can help him solve this puzzle using a computer.

Input Format

The input format is:

The first line contains an integer nn (n<10n<10), meaning there are nn initial positions below.

Next, there are nn lines. Each line contains a string (length <20<20), representing the starting position.

For example: ****** means there are 66 empty cells.

L**** means the leftmost cell is the letter L, and to its right there are 44 empty cells.

Output Format

Output nn numbers. For each position, if Xiaoming plays first and Master K always uses the strongest moves, output Xiaoming’s best possible result.

1 means Xiaoming can win.

-1 means Xiaoming will definitely lose.

0 means Xiaoming can force a draw.

4
***
L**L
L**L***L
L*****L
0
-1
1
1

Hint

Time limit: 1 second, 256M. Lanqiao Cup, 2017, the 8th National Finals.

Translated by ChatGPT 5