# Seven and a half P97400

Statement

html

‘Warning, this problem is not easy! ‘Do you know to play to seven and a half? In this game of chance your aim is to win to the dealer. First, you play a hand of seven and a half, and then plays the dealer: the hand with the highest total wins as long as it doesn’t exceed. ‘During the years, huge fortunes have changed of hands because of this game! (Well, the previously sentence is probably false, but it does its function).

We will play the following simplified version of seven an a half. First, is the turn of the player: he will ask for cards until he decides to stand. The cards in game are the numbers from 1 to 7 (their value is the number), and the 3 face cards (their value is a half). The score of the player is the sum of the points of the cards in the moment he stands, with the only restriction that he cannot exceed 7.5 points; if so, he would obtain the score −1. Then, the dealer plays, with the aim of improve the score obtained by the player. The game ends when the dealers stands, busts or there is not more cards. Wins the game the one (player or dealer) that obtains the maximal score. In a event of a tie, the player wins.

In this problem you will have to help a player to beat the dealer, computing the probability that he has to win if he has ask for another card, and the probability that he has if he decides to stand. We assure you that the player as well as the dealer play perfectly (the player always takes the decision that has the greatest probability of success, and the dealer stops asking for cards as soon as his score is greater than the score of the player).

Input

A number n<20 in a line, that describes the number of cases. Then, n lines, each one of them describing a case: a character C followed by exactly 8 numbers, separated by spaces. The character c describes the first card that the player has received, and it is the letter ’F’ (to indicate that he has received a face card) or one of the numbers from ’1’ to ’7’, to indicate that he has received a number. The other 8 numbers are the number of cards of each type that remains in the deck after being given this first card: the first of the 8 numbers contains the number of face cards, and the other seven the number of cards of score from 1 to 7.

Your program must solve all the cases in 1 second of time.

Output Your program must print, for each case, two percentages in a line, separated by spaces. The first percentage is the probability that, given the deck and the initial card, has the player to win if he asks for other card; the second percentage is the probability that he will have to win if he stands. It must print the precentages without decimals, rounding to the nearest integer –the input will be such that any probability will have the decimal places between 0.499999 and 0.500001, to avoid rounding errors.

Public test cases
• Input

```8
7 12 4 4 4 4 4 4 3
6 12 4 4 4 4 4 3 4
5 12 4 4 4 4 3 4 4
4 12 4 4 4 3 4 4 4
3 12 4 4 3 4 4 4 4
2 12 4 3 4 4 4 4 4
1 12 3 4 4 4 4 4 4
F 11 4 4 4 4 4 4 4
```

Output

```31% 83%
28% 56%
27% 36%
28% 23%
28% 12%
34% 6%
39% 2%
47% 0%
```
• Input

```7
7 4 2 1 1 3 1 0 1
4 4 2 1 1 3 1 0 1
F 4 2 1 1 3 1 0 1
7 6 0 0 0 0 0 0 1
F 6 0 0 0 0 0 0 1
1 6 0 0 0 0 0 0 1
F 3 1 1 1 0 0 0 0
```

Output

```31% 82%
28% 20%
46% 0%
86% 71%
43% 0%
43% 14%
100% 0%
```
• Information
Author
Omer Giménez
Language
English
Translator
Carlos Molina
Original language
Spanish
Other languages
Spanish
Official solutions
C++
User solutions
C++