COdeforces Gym-101291K Six Sides

http://codeforces.com/gym/101291/attachments

Six Sides

Two players play a simple game. Each brings their own six-sided die with specified values on thesix faces. Each die is fair; that is, when it is thrown, each of its six faces is equally likely to comeup on top.

The first player throws the first die and the second throws the second die. If the values shown onthe top of the dice differ, the player with the higher value wins. If the values are the same, bothplayers throw the dice again.

Given two dice with specific values, what is the probability that the first player wins?

Input

The first line of input contains six space-separated integers, representing the values written on thefirst player’s die.

The second line of input contains the values on the second player’s die in the same format.

It is guaranteed that all the values are between 1 and 6, inclusive.

Output

Print, on a single line, a floating-point value representing the probability that the first player wins,rounded and displayed to exactly five decimal places. The value should be printed with one digitbefore the decimal point and five digits after the decimal point. The sixth digit after the decimalpoint of the exact answer will never be 4 or 5 (eliminating complex rounding considerations).

Sample Input

1 2 3 4 5 6
1 2 3 4 5 6

Sample Output

0.50000

Sample Input

4 4 4 4 1 1
3 3 3 3 3 3

Sample Output

0.66667

直接暴力比较

#include 
int main()
{
     
    int a[10],b[10];
    int i,j;
    for(i=0; i<6; i++)
    {
     
        scanf("%d",&a[i]);
    }
    for(i=0; i<6; i++)
    {
     
        scanf("%d",&b[i]);
    }
    int c=0,d=0;
    for(i=0; i<6; i++)
    {
     
        for(j=0; j<6; j++)
        {
     
            if(a[i]>b[j])
                c++;
            else if(a[i]<b[j])
                d++;
        }
    }
    printf("%.5f",c*1.0/(c+d));
    return 0;
}

你可能感兴趣的:(COdeforces Gym-101291K Six Sides)