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 <stdio.h>
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;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值