PROBLEM STATEMENT
John and Brus are training for a card game tournament.
There they will be playing Black Jack.
Black Jack is played using a standard deck containing 52 distinct cards.
Each card can be represented as a two-character string where the first character is the rank ('2'
- '9' for ranks Two through Nine, 'T' for Ten, 'J' for Jack, 'Q' for Queen, 'K' for King and 'A'
for Ace) and the second character is the suit ('S' for Spades, 'C' for Clubs, 'D' for Diamonds and
'H' for Hearts).
For example, the Jack of Spades can be represented as "JS" and the Nine of Hearts as "9H".
Each time a player receives a card from the deck, his score increases by the card's value.
Ranks Two through Ten have values of 2 - 10, respectively.
Jacks, Queens and Kings each have a value of 10, and Aces have a value of 11.
Brus randomly shuffles the full card deck and gives John one or more cards from the top of the deck.
You are given a vector cards, where each element represents a single card given to John
in this initial step.
John will then take extra cards from the top of the deck, one by one, until his score is greater
than or equal to 21.
Return the expected number of extra cards that John will take.
DEFINITION
Class:TheBlackJackDivOne
Method:expected
Parameters:vector
Returns:double
Method signature:double expected(vector cards)
NOTES
-The returned value must be accurate to within a relative or absolute value of 1E-9.
CONSTRAINTS
-cards will contain between 1 and 50 elements, inclusive.
-Each element of cards will contain exactly two characters, where the first character is '2'-'9',
'T', 'J', 'Q', 'K' or 'A', and the second character is 'S', 'C', 'D' or 'H'.
-All elements of cards will be distinct.
EXAMPLES
0)
{"JS"}
Returns: 2.105854341736695
1)
{"KD", "8S"}
Returns: 1.08
John will take the second extra card only if the first one is Two.
2)
{"KD", "2S", "2C", "2D", "2H"}
Returns: 1.0
The same situation, but here there are no Twos left in the deck.
3)
{"AS", "KS", "9S", "JC", "2D"}
Returns: 0.0
Here John's score is already more than 21.
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.