/* ******************************************************************************** */
#include <iostream> //
#include <cstdio> //
#include <cmath> //
#include <cstdlib> //
#include <cstring> //
#include <vector> //
#include <ctime> //
#include <deque> //
#include <queue> //
#include <algorithm> //
#include <map> //
#include <cmath> //
using namespace std; //
//
#define pb push_back //
#define mp make_pair //
#define X first //
#define Y second //
#define all(a) (a).begin(), (a).end() //
#define fillchar(a, x) memset(a, x, sizeof(a)) //
//
typedef pair< int , int > pii; //
typedef long long ll; //
typedef unsigned long long ull; //
//
#ifndef ONLINE_JUDGE //
void RI(vector< int >&a, int n){a.resize(n); for ( int i=0;i<n;i++) scanf ( "%d" ,&a[i]);} //
void RI(){} void RI( int &X){ scanf ( "%d" ,&X);} template < typename ...R> //
void RI( int &f,R&...r){RI(f);RI(r...);} void RI( int *p, int *q){ int d=p<q?1:-1; //
while (p!=q){ scanf ( "%d" ,p);p+=d;}} void print(){cout<<endl;} template < typename T> //
void print( const T t){cout<<t<<endl;} template < typename F, typename ...R> //
void print( const F f, const R...r){cout<<f<< ", " ;print(r...);} template < typename T> //
void print(T*p, T*q){ int d=p<q?1:-1; while (p!=q){cout<<*p<< ", " ;p+=d;}cout<<endl;} //
#endif // ONLINE_JUDGE //
template < typename T> bool umax(T&a, const T&b){ return b<=a? false :(a=b, true );} //
template < typename T> bool umin(T&a, const T&b){ return b>=a? false :(a=b, true );} //
template < typename T> //
void V2A(T a[], const vector<T>&b){ for ( int i=0;i<b.size();i++)a[i]=b[i];} //
template < typename T> //
void A2V(vector<T>&a, const T b[]){ for ( int i=0;i<a.size();i++)a[i]=b[i];} //
//
const double PI = acos (-1.0); //
const int INF = 1e9 + 7; //
//
/* -------------------------------------------------------------------------------- */
struct Gauss {
const static int maxn = 1e3 + 7;
double A[maxn][maxn];
int n;
double * operator [] ( int x) {
return A[x];
}
/** 要求系数矩阵可逆
A是增广矩阵,A[i][n]是第i个方程右边的常数bi
运行结束后 A[i][n]是第i个未知数的值 **/
void solve() {
for ( int i = 0; i < n; i ++) {
int r = i;
for ( int j = i + 1; j < n; j ++) {
if ( fabs (A[j][i]) > fabs (A[r][i])) r = j;
}
if (r != i) for ( int j = 0; j <= n; j ++) swap(A[r][j], A[i][j]);
for ( int j = n; j >= i; j --) {
for ( int k = i + 1; k < n; k ++) {
A[k][j] -= A[k][i] / A[i][i] * A[i][j];
}
}
}
for ( int i = n - 1; i >= 0; i --) {
for ( int j = i + 1; j < n; j ++) {
A[i][n] -= A[j][n] * A[i][j];
}
A[i][n] /= A[i][i];
}
}
};
Gauss solver;
int c, n;
double p;
int hsh[22][22];
void add( int x, int y, int z) {
solver[c][x] += 1;
solver[c][y] += -p;
solver[c ++][z] += p - 1;
}
void init() {
fillchar(solver.A, 0);
c = 0;
for ( int i = 0; i < 20; i ++) {
for ( int j = i; j < 20; j ++) {
int win = i + 1, unwin = max(i - 2, 0);
add(hsh[i][j], hsh[min(win, j)][max(win, j)], hsh[unwin][j]);
}
}
solver[c ++][hsh[19][20]] = 1;
for ( int i = 0; i < c - 1; i ++) {
solver[i][n] = 1;
}
}
void pre_init() {
int c = 0;
for ( int i = 0; i < 20; i ++) {
for ( int j = i; j < 20; j ++) {
hsh[i][j] = c ++;
}
}
hsh[19][20] = c ++;
solver.n = n = c;
}
int main() {
#ifndef ONLINE_JUDGE
freopen ( "in.txt" , "r" , stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
pre_init();
while (cin >> p) {
init();
solver.solve();
printf ( "%.10f\n" , solver[0][n]);
}
return 0;
}
/* ******************************************************************************** */
|