using System; namespace No425{ public class Program{ public static void Main(string[] args){ var sr = new StreamReader(); //--------------------------------- var p0 = sr.Next() / 100.0m; var q = sr.Next() / 100.0m; var memo = new decimal[21, 101].ToJaggedArray(); Ex.Fill(memo, decimal.MinValue); Func dfs = null; dfs = (cnt, p) =>{ var i = (int)(p * 100m); //メモされていたらそれを返す if(memo[cnt][i] != decimal.MinValue) return memo[cnt][i]; //20回以上あいこだったらとりあえずなんか返す if(cnt >= 20) return 0.114514810m; //必勝法で勝利 var a = p / 2.0m; //必勝法であいこ var b = p / 2.0m * dfs(cnt + 1, Ex.Clamp(0.0m, p - q, 1.0m)); //必勝法を使わずに勝利 var c = (1 - p) / 3.0m; //必勝法を使わずにあいこ var d = (1 - p) / 3.0m * dfs(cnt + 1, Ex.Clamp(0.0m, p + q, 1.0m)); //メモしながら返す return memo[cnt][i] = a + b + c + d; }; Console.WriteLine((dfs(0, p0) + 1) / 3.0m); //--------------------------------- } } public static class ExMethod{ public static T[][] ToJaggedArray(this T[,] src){ var x = src.GetLength(1); var y = src.GetLength(0); var ret = new T[y][]; for(var i = 0; i < y; i++){ ret[i] = new T[x]; for(var j = 0; j < x; j++){ ret[i][j] = src[i, j]; } } return ret; } } public class Ex{ public static T Clamp(T min, T src, T max) where T:IComparable{ if(src.CompareTo(max) > 0) return max; if(src.CompareTo(min) < 0) return min; return src; } public static void Fill(T[] src, T val){ for(var i = 0; i < src.Length; i++){ src[i] = val; } } public static void Fill(T[][] src, T val){ for(var i = 0; i < src.Length; i++){ Fill(src[i], val); } } } public class StreamReader{ private readonly char[] _c = {' '}; private int _index = -1; private string[] _input = new string[0]; private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput()); public T Next(){ if(_index == _input.Length - 1){ _index = -1; while(true){ string rl = _sr.ReadLine(); if(rl == null){ if(typeof(T).IsClass) return default(T); return (T)typeof(T).GetField("MinValue").GetValue(null); } if(rl != ""){ _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries); break; } } } return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture); } } }