题目
https://cn.vjudge.net/problem/Gym-102190B
题意
两个人玩游戏 互抽牌 相同可以消去 给你每个人手中牌的数目,问先手赢得概率
思路
题目说 一定含有一张鬼牌 分情况讨论鬼牌在自己手里还是在对方手里
#include <bits/stdc++.h>using namespace std;
char a[1000006];
char b[1000006];
double dp[1000006][3];
int main()
{int t;dp[0][1] = 0;dp[0][2] = 1;for(int i = 1; i <= 1000000; i++){dp[i][1] = 1.0 - dp[i-1][2];dp[i][2] = (double)(1.0 + (double)i*(1-dp[i-1][1]))/(double)(i+2);}scanf("%d",&t);while(t--){int n;scanf("%d",&n);scanf("%s%s",a,b);int z=0;int f;for(int i = 0; i < n; i++){if(a[i] == '1'&&b[i] == '0')f = 1;else if(a[i] == '0'&&b[i] == '1')f = 2;else if(a[i] == '1'&&b[i] == '1')z++;}printf("%.12f\n",dp[z][f]);}return 0;
}