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;
}