Computer College college Student Program Design Contest (2015 ' 11) 1003 play Dice

Source: Internet
Author: User
1003 playing Dice Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Problem Description Nias and ains are especially fond of playing dice, and they all think they have more to play than each other.
Finally one day, they decided to use the dice to a showdown.
The general dice play is not enough to reflect their level, so they created a set of play to PK:
First of all, throw 3 dice each, then you can choose one of the dice to roll again (of course, you can also give up this step), and finally, compare the size of the throwing result, the big side wins, the same words for a draw.
The size comparison rules are:
Three dice of the same number are called three, two dice of the same number are called pairs, and only one number of dice becomes a hash. Three > Pair > Loose. When both results are three, direct comparison of the size of three digits; when there are pairs, compare the size of the number of pairs, if the same, and then compare the size of the remaining dice; only the size of the largest number, if the same, compared to the size of the second large number, is the same, the last comparison of the smallest number of size.

Now that Nias has cast 3 dice, there is one more chance to choose one of the dice to rejoin (or not), and he already knows the Ains's final throw, and Nias the probability of winning.

Input data The first behavior of an integer t, indicates that there is a T group of test data.
Next t row, each row 6 1~6 integers, the first three represents Nias first throw result, the latter three represents AIAs final throw result.
Output please export Nias winning probability, the result retains 3 decimal places, each group output occupies one row.

Sample Input
4 2 3 5 3 3 4 3 3 1 2 2 2 6 2 1 5 4 3 1 2 3 4 4-1
Sample Output
0.333 0.167 1.000 0.000

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <queue> #include <stack > #include <math.h> #include <vector> #include <map> #include <set> #include <cmath>
include<string> #include <algorithm> #include <iostream> #define EXP 1e-10 using namespace std;
const int N = 25;
const int M = 1005;
const int inf = 1000000007;
const int mod = 2009;
    int fun (int a,int b,int c) {if (a==b&&b==c) return 3; else if (a==b| | a==c| |
    B==C) return 2;
return 1;
    int solve (int a,int b,int c,int d,int e,int f) {int k1=fun (a,b,c), K2=fun (d,e,f), x1,x2,y1,y2;
    if (K1&GT;K2) return 3;
    else if (K1&LT;K2) return 1;
        if (k1==3) {if (a>d) return 3;
        else if (a<d) return 1;
    else return 2;
        else if (k1==2) {if (a==b) x1=a,x2=c;
    else if (a==c) x1=a,x2=b;    else if (b==c) x1=b,x2=a;
        if (d==e) y1=d,y2=f;
        else if (d==f) y1=d,y2=e;
        else if (e==f) Y1=e,y2=d;
            if (x1!=y1) {if (x1>y1) return 3;
        if (x1<y1) return 1;
        } if (X2>y2) return 3;
        else if (x2<y2) return 1;
    else return 2;
        else if (k1==1) {if (a<b) swap (A,B);
        if (a<c) swap (A,C);
        if (b<c) swap (B,C);
        if (d<e) swap (d,e);
        if (d<f) swap (D,F);
        if (e<f) swap (E,F);
            if (A!=d) {if (a>d) return 3;
        else return 1;
            } if (b!=e) {if (b>e) return 3;
        else return 1;
  } if (c>f)          return 3;
        else if (c<f) return 1;
    return 2;
return 0;
    int main () {int t,a,b,c,d,e,f,ans,i;
    Double Sol;
    scanf ("%d", &t);
        while (t--) {sol=0;
        scanf ("%d%d%d%d%d%d", &a,&b,&c,&d,&e,&f);
            if (Solve (a,b,c,d,e,f) ==3) {puts ("1.000");
        Continue
        For (Ans=0,i=1 i<=6; i++) if (Solve (i,b,c,d,e,f) ==3) ans++;
        Sol=max (SOL,ANS*1.0/6);
        For (Ans=0,i=1 i<=6; i++) if (Solve (a,i,c,d,e,f) ==3) ans++;
        Sol=max (SOL,ANS*1.0/6);
        For (Ans=0,i=1 i<=6; i++) if (Solve (a,b,i,d,e,f) ==3) ans++;
        Sol=max (SOL,ANS*1.0/6);
    printf ("%.3f\n", Sol);
return 0;
 }

Always looking at once space in a daze, those who say not separate friends, turn around, strangers. Familiar, quiet, quiet, left, left, unfamiliar, unfamiliar, disappeared, disappeared, strangers.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.