結果
問題 | No.301 サイコロで確率問題 (1) |
ユーザー |
![]() |
提出日時 | 2015-11-14 00:41:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 23 ms / 1,000 ms |
コード長 | 1,357 bytes |
コンパイル時間 | 822 ms |
コンパイル使用メモリ | 75,664 KB |
実行使用メモリ | 6,940 KB |
最終ジャッジ日時 | 2024-09-13 16:32:21 |
合計ジャッジ時間 | 1,259 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 |
ソースコード
#include <iostream>#include <vector>#include <iomanip>using namespace std;typedef long long ll;typedef double ld;int T;ll k;ld p=1;vector<vector<ld> > powmat[64];vector<vector<ld> > matmul(vector<vector<ld> >& a, vector<vector<ld> >& b) {int n = a.size();vector<vector<ld> > c(n, vector<ld>(n));for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)for (int k = 0; k < n; k++)c[i][j] = (c[i][j] + (ld)a[i][k] * b[k][j]);return c;}vector<vector<ld> > matpow(ll k) {vector<vector<ld> > ret(7, vector<ld>(7));for (int i = 0; i < 7; i++)ret[i][i] = 1;for(int i=0;i<64;i++)if((k>>i&1)==1)ret=matmul(ret,powmat[i]);return ret;}void otaku(vector<vector<ld> > mat){powmat[0]=mat;for(int i=1;i<64;i++)powmat[i]=matmul(powmat[i-1],powmat[i-1]);}int main(){p/=6;cout<<fixed<< setprecision(16);cin>>T;vector<vector<ld> > mat(7, vector<ld>(7));for(int i=0;i<5;i++)mat[i][i+1]=1.0;for(int i=0;i<6;i++)mat[5][i]=p;mat[5][6]=mat[6][6]=1;otaku(mat);for(int _=0;_<T;_++){cin>>k;if(k<100){vector<vector<ld> > ret=matpow(k);ld ggg=ret[5][6];ld fff=0.0;for(int i=0;i<5;i++)fff+=ret[5][i];cout<<ggg/(1.0-fff)<<endl;}else{cout<<k+1<<".666666666666666\n";}}}