Black Jack.accepts:0submissions:61Time limit:2000/1000 MS (java/others)Memory limit:65536/65536 K (java/others)Problem description
21 o'clock also known as Blackjack (English: Blackjack), originated in France, has spread to all over the world. 21 o'clock, it is a gambling game played with poker. It is also the only kind of gambling game that can beat the banker in the probability in the gambling market. ——— from a good encyclopedia we define the 21-point rule as follows, slightly different from the original rule. The card points are as follows: A 2 3 4 5 6 7 8 9 J Q ka as 1 points jqk all as 10 points. We assume that the casino prepares a lot of sub-cards, that is, you can assume that every time you touch each card is the same probability. Players have two people, respectively, the banker and the idle home. At first, both of them took two cards, and two people could see each other's cards. The Idle House first operation, each time may call the card or stops the call card. If the call card, from the card heap to take a card, once the call hand hand more than 21 points, directly sentenced to lose, called "burst point", otherwise always called until the stop call card, turn to the dealer. After the turn of the dealer, and the same as the idle call or stop the call card, once the point is also directly sentenced to lose. If there is no explosion point, who wins the number of points, the same level of points. Give you two cards, if the idle home winning >50% output "YES", otherwise output "NO" Oh, yes, everyone is very smart.
Enter a description
The first line is a number Test (test<=100000). Represents the number of data groups. Below each set of data, a 4 character string, the first two characters to represent the cards of the house, the last two of the dealer's. (denoted by T 10)
Output description
For each set of data output "YES" or "NO", indicating whether the idle home has more than 50% of the winning percentage.
Input sample
1ttt9
Output sample
yes//It is obvious that the house does not call cards, the dealer only 2/13 chance to win.
DP1[A][B] that the idle home and the dealer points are A and B when the idle home call card when the winning percentage, dp2[a][b] that the idle home and dealer points are A and B when the banker called when the player's winning.
The answer is DP1 (A, b) >0.5.
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#defineREP (I,A,B) for (int i=a;i<=b;i++)#defineMS0 (a) memset (A,0,sizeof (a))using namespaceStd;typedefLong Longll;Const intmaxn= to;Const intinf=1<< in;Const Doubleeps=0.0000000001;CharS[MAXN];intN;intb;DoubleDP1[MAXN][MAXN];DoubleDP2[MAXN][MAXN];intShuCharx) { if(x=='A')return 1; if(x=='T'|| x=='J'|| x=='K'|| x=='Q')return Ten; returnX-'0';}DoubleDFS2 (intAintb) { Double&res=Dp2[a][b]; if(res>-eps)returnRes; if(a<=b)returnres=0; Res=0; REP (i,1,9){ if(b+i<= +) RES+=DFS2 (a,b+i)/ -; Elseres+=1.0/ -; } REP (I,1,4){ if(b +Ten<= +) RES+=DFS2 (a,b+Ten)/ -; Elseres+=1.0/ -; } returnRes;}DoubleDFS1 (intAintb) { Double&res=Dp1[a][b]; if(res>-eps)returnRes; Res=0; REP (i,1,9)if(a+i<= +) RES+=DFS1 (A+I,B)/ -; REP (i,1,4)if(A +Ten<= +) RES+=DFS1 (A +Ten, b)/ -; Res=Max (DFS2 (A, B), res); returnRes;}intMain () {Freopen ("In.txt","R", stdin); intT;cin>>T; while(t--) {scanf ("%s", s); A=shu (s[0]) +shu (s[1]); b=shu (s[2]) +shu (s[3]); REP (i,1, maxn-1) REP (J,1, maxn-1) dp1[i][j]=dp2[i][j]=-1.0; Puts (DFS1 (A, b)>0.5+eps?"YES":"NO"); } return 0;}
View Code
Bestcoder #67 div2 1003 Black Jack probability dp