結果

問題 No.301 サイコロで確率問題 (1)
ユーザー tjaketjake
提出日時 2015-12-05 03:19:58
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,951 bytes
コンパイル時間 3,826 ms
コンパイル使用メモリ 75,556 KB
実行使用メモリ 11,988 KB
最終ジャッジ日時 2023-10-12 15:32:50
合計ジャッジ時間 5,345 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-14

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef __float128 lld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

int main() {
  int t;
  lld mat[7][7], mat2[7][7], res[7][7];
  lld a[7], b[7];
  lld ans;
  cin >> t;
  while(t--) {
    ll n;
    cin >> n;

    rep(i, 7) rep(j, 7) mat[i][j] = res[i][j] = 0;
    rep(i, 6) mat[5][i] = 1.0/6; mat[5][6] = mat[6][6] = 1.;
    rep(i, 5) mat[i][i+1] = 1.;
    rep(i, 7) res[i][i] = 1.;

    if(n>6) {
      ll r = n-5;
      while(r) {
        if(r%2) {
          rep(i, 7) rep(j, 7) {
            mat2[i][j] = 0;
            rep(k, 7) mat2[i][j] += mat[i][k]*res[k][j];
          }
          rep(i, 7) rep(j, 7) res[i][j] = mat2[i][j];
        }
        rep(i, 7) rep(j, 7) {
          mat2[i][j] = 0;
          rep(k, 7) mat2[i][j] += mat[i][k]*mat[k][j];
        }
        rep(i, 7) rep(j, 7) mat[i][j] = mat2[i][j];
        r /= 2;
      }
    }

    lld left = 0, right = 10e18;
    while(1) {
      lld mid = (left + right) / 2.0;
      a[0] = 0;
      a[6] = 1;
      repl(i, 1, 5) {
        a[i] = 0;
        rep(j, 6) {
          if(i-1-j<0) {
            a[i] += mid + 1;
          } else {
            a[i] += a[i-1-j] + 1;
          }
        }
        a[i] /= 6;
      }

      if(n>6) {
        rep(i, 7) {
          b[i] = 0;
          rep(j, 7) {
            b[i] += a[j]*res[i][j];
          }
        }
        rep(i, 7) a[i] = b[i];
      }
      ans = n<6 ? a[n] : a[5];
      if(mid < ans) {
        if(left-EPS < mid && mid < left + EPS) break;
        left = mid;
      } else {
        if(right-EPS < mid && mid < right + EPS) break;
        right = mid;
      }
    }

    printf("%.16Lf\n", (ld)ans);

  }
  return 0;
}
0