Problem Description Nias and ains are particularly fond of playing dice, and they think they play more than the other side.
Finally one day, they decided to use the dice to a showdown!
The general dice play has not been enough to reflect their level, so they created a set of play to PK:
First, each person throws 3 dice, after that, you can choose one of the dice to re-throw (of course, you can give up this step), and finally, compare the size of the throwing results, the result of the big side wins, the same thing is a draw.
The size comparison rules are:
Three of the same number of dice is called Three, two of the same number of dice is called a pair; only one number of dice becomes a scatter card. Three > Pairs > Scatter. When both ends are three, directly compare the size of three numbers, all have pairs, first compare the size of the child number, if the same, and then compare the size of the rest of the dice number, all only when the size of the largest number of cards, if the same, and then compare the size of the second-largest number, but also the same, and finally the smallest number size.
Now Nias has cast 3 dice, and one more chance to choose one of the dice to re-cast (or not), and he already knew the ains of the final throw results, to find out the probability of Nias win. Input data first behaves as an integer t, which indicates that there is a T group of test data.
Next T line, 6 1~6 per line of integers, the first three represents Nias first throw results, the last three represents AIAs final throw results. Output Nias The probability of winning, the result is 3 decimal places, and each group of output takes up one row. Sample Input42 3 5 3 3 3 1 2 2 2 1 5 4 + 2 3 4 4 1 Sample Output0.3330.1671.0000.000
Brute Force enumeration.
#include <cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;intx[5],a[5],b[5];intT;intFZ,FM;Doubleans;intFlag;inttot;voidcopy () {a[1]=x[1]; a[2]=x[2]; a[3]=x[3];}intCheak () {sort (a+1, A +4); Sort (b+1, B +4); intLva,lvb; if(a[1]==a[2]&&a[2]==a[3]) lva=3; Else if(a[2]==a[3]|| a[1]==a[2]) lva=2; ElseLva=1; if(b[1]==b[2]&&b[2]==b[3]) lvb=3; Else if(b[2]==b[3]|| b[1]==b[2]) lvb=2; Elselvb=1; if(LVA>LVB)return 1; Else if(LVA<LVB)return 0; Else if(lva==Lvb) { if(lva==3) { if(a[1]>b[1])return 1; Else return 0; } Else if(lva==2) { if(a[2]>b[2])return 1; Else if(a[2]<b[2])return 0; Else { intU1,U2; if(a[2]==a[3]) u1=a[1]; Elseu1=a[3]; if(b[2]==b[3]) u2=b[1]; Elseu2=b[3]; if(U1>U2)return 1; Else return 0; } } Else if(lva==1) { if(a[3]>b[3])return 1; Else if(a[3]<b[3])return 0; Else { if(a[2]>b[2])return 1; Else if(a[2]<b[2])return 0; Else { if(a[1]>b[1])return 1; Else if(a[1]<b[1])return 0; Else return 0; } } return 0; } }}intMain () {scanf ("%d",&T); while(t--) {scanf ("%d%d%d%d%d%d", &x[1],&x[2],&x[3],&b[1],&b[2],&b[3]); Copy (); Flag=Cheak (); FZ=Flag; if(FZ) printf ("1.000\n"); Else if(fz==0) {ans=0; FM=0; for(intI=1; i<=3; i++) {tot=0; for(intj=1; j<=6; j + +) {copy (); A[i]=J; Flag=Cheak (); Tot=tot+Flag; } if(tot==0)Continue; Ans=max (ans,1.0*tot/6); } printf ("%.3lf\n", ans); } } return 0;}
HDU Computer Academy Tournament 1003 Play Dice