#include #include #include #include #include typedef long long ll; using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) double p0, q; bool solve(){//取り出す順番の添字を返す // 0 gu- 1 tyki 2 pa- int pkamo = -1, pnegi = -1; int kamo = rand() % 3; int negi = rand() % 3; int waza = 0; double p; while(kamo == negi){ pkamo = kamo, pnegi = negi; //kamoの今回の手は vector vkamo; rep(i, 3){ if(i != pkamo) vkamo.push_back(i); } int tmp = rand() % 2; kamo = vkamo[tmp]; //negiが必勝法を使う確率を求める if(waza == 0){//hazimete p = p0; }else if(waza == 1){//前回使用 p -= q; if(p < 0) p = 0; }else if(waza == 2){//前回使用していない p += q; if(p > 1) p = 1; } double nowp = rand() % 101; if(nowp <= p){//必勝しよう negi = (pkamo + 1) % 3; waza = 1; }else{//しない negi = rand() % 3; waza = 2; } } //判定 // printf("%d %d\n", negi, kamo); if(negi == 0 && kamo == 1) return true; if(negi == 1 && kamo == 2) return true; if(negi == 2 && kamo == 0) return true; return false; } int main(void){ cin >> p0 >> q; int win = 0; rep(i, 1000000){ if(solve()) win++; } printf("%.9f\n", (double)win / 1000000.0); return 0; }