ZOJ 3468 Dice War

Dice War

Time Limit: 2 Seconds       Memory Limit: 65536 KB       Special Judge

Dice war is a board game. In each turn, the attacker will choose a pile of dices to attack the defender's pile of dices. They will roll the all dices, and the attacker will win if and only if the total number on all his dices is larger than the defenders. After a successful attack, the attacker's pile of dices will split into two piles, while one of them has only one dice. If the attacker loses, this pile will lose all dices except one. An attack cannot be made with a pile of one single dice.

Input
Multiple cases. Each case contains two number of dices in the attacker's pile and the diffender's pile. In the game, number of dices in a pile will be no more than 8.
Output
For each case, output the probability of attack success in a single line. Error no more than 1e-4 will be accepted.
Sample Input
3 2
2 1
Sample Output
0.7785493827160493
0.8379629629629629

Author:  CUI, Tianyi



一开始理解错题意了,想的很复杂然后就在那推公式了。。

纯暴力即可。。


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>

using namespace std;

#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define DWN(i,h,l) for(int i=(h);i>=(l);--i)
#define CLR(vis) memset(vis,0,sizeof(vis))
#define MST(vis,pos) memset(vis,pos,sizeof(vis))
#define MAX3(a,b,c) max(a,max(b,c))
#define MAX4(a,b,c,d) max(max(a,b),max(c,d))
#define MIN3(a,b,c) min(a,min(b,c))
#define MIN4(a,b,c,d) min(min(a,b),min(c,d))
#define PI acos(-1.0)
#define INF 0x7FFFFFFF
#define LINF 1000000000000000000LL
#define eps 1e-8

typedef long long ll;

int z[9][55];
double cal[9][55];

int main()
{
    CLR(z),CLR(cal);
    FOR(a,1,6)
    {
        FOR(b,1,6)
        {
            FOR(c,1,6)
            {
                FOR(d,1,6)
                {
                    FOR(e,1,6)
                    {
                        FOR(f,1,6)
                        {
                            FOR(g,1,6)
                            {
                                FOR(h,1,6)
                                {
                                    z[8][a+b+c+d+e+f+g+h]++;
                                }
                                z[7][a+b+c+d+e+f+g]++;
                            }
                            z[6][a+b+c+d+e+f]++;
                        }
                        z[5][a+b+c+d+e]++;
                    }
                    z[4][a+b+c+d]++;
                }
                z[3][a+b+c]++;
            }
            z[2][a+b]++;
        }
        z[1][a]++;
    }
    FOR(a,1,8)
    {
        int res=(int)pow(6,a);
        FOR(b,1,6*a)
        {
            cal[a][b]=(double)z[a][b]/res;
        }
    }
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        double ans=0.0;
        FOR(i,2,6*n)
        {
            FOR(j,1,i-1)
             ans+=cal[n][i]*cal[m][j];
        }
        printf("%.6lf\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值