Alice and Bob are playing games again !!!! In the beginning, the former has a Yuan, and the latter has B yuan. Each time you play, the probability that each person wins is half-open. If C is the minimum value of A and B, then each time you play, if anyone loses, the winner is C yuan. Ask Alice the probability of winning and the expected number of game disks!
Thought: It looks like it will be iterated! The formula is not good... The probability of discovery is 0.5, and the error range is 1e-5. The probability is negligible as long as it reaches a certain depth!
#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <string>#include <algorithm>#include <queue>#include <set>#include <map>using namespace std;typedef long long LL;#define REP(_,a,b) for(int _ = (a); _ <= (b); _++)int a,b;int gcd(int a,int b) { if(!b) return a; else return gcd(b,a%b);}double dfs(int x,int y,int dep) { if(dep > 30 || x==0) return 0.0; if(y==0) return 1; if(x > y) { return dfs(x-y,y*2,dep+1)/2+dfs(x+y,0,dep+1)/2; }else{ return dfs(0,y+x,dep)/2+dfs(x+x,y-x,dep+1)/2; }}double dfs1(int x,int y,int dep) { if(dep > 30) return 1; if(x==0) return 0; if(y==0) return 0; if(x > y) { return 1+dfs1(x-y,y*2,dep+1)/2; }else{ return 1+dfs1(x*2,y-x,dep+1)/2; }}int main(){ int ncase,T=1; cin >> ncase; while(ncase--) { scanf("%d%d",&a,&b); if(a==b) { printf("Case %d: 1.000000 0.500000\n",T++); }else{ int g = gcd(a,b); int t1 = a/g; int t2 = b/g; double p = dfs(t1,t2,0); double e = dfs1(t1,t2,1); printf("Case %d: %.6lf %.6lf\n",T++,e,p); } } return 0;}
Va 12585 poker End Games