计算机学院大学生程序设计竞赛(2015’11)1003 玩骰子

1003 玩骰子

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
  Nias与Ains都特别喜欢玩骰子,而且都自以为比对方玩得更溜。
  终于有一天,他们决定用骰子来一决高下!
  一般的骰子玩法已经不足以体现他们的水平了,于是他们自创了一套玩法来PK:
首先,每人掷3个骰子;之后,可以选择其中一个骰子重新掷(当然也可以放弃这一步),最后,比较投掷结果的大小,结果大的那方获胜,一样的话为平局。
  大小比较规则为:
  三个一样数字的骰子称为三条;两个一样数字的骰子称为对子;只有一个数字的骰子成为散牌。三条>对子>散牌。当双方结果都为三条时,直接比较三条数字的大小;都有对子时,先比较对子数字的大小,若相同,再比较剩下的骰子的数字的大小;都只有散牌时,先比较最大的数字的大小,若相同,再比较次大的数字的大小,还相同,最后比较最小的数字的大小。

  现在Nias已经投了3个骰子,还剩一次机会可以选择其中一个骰子重新投(或不选),而且他已经知道了Ains的最后投掷结果,求Nias获胜的概率有多大。
 

Input
输入数据第一行为一个整数T,表示有T组测试数据。
接下来T行,每行6个1~6的整数,前三个表示Nias第一次的投掷结果,后三个表示Aias最终的投掷结果。
 

Output
请输出Nias获胜的概率,结果保留3位小数,每组输出占一行。
 

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>k2)
        return 3;
    else if(k1<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
",sol);
    }
    return 0;
}

总是望着曾经的空间发呆,那些说好不分开的朋友不在了,转身,陌路。 熟悉的,安静了, 安静的,离开了, 离开的,陌生了, 陌生的,消失了, 消失的,陌路了。快哭了

原文地址:https://www.cnblogs.com/im0qianqian/p/5989690.html