結果
| 問題 |
No.76 回数の期待値で練習
|
| コンテスト | |
| ユーザー |
mugen_1337
|
| 提出日時 | 2021-12-02 14:07:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 5,000 ms |
| コード長 | 2,486 bytes |
| コンパイル時間 | 1,620 ms |
| コンパイル使用メモリ | 194,432 KB |
| 最終ジャッジ日時 | 2025-01-26 02:48:59 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 |
ソースコード
#include"bits/stdc++.h"
using namespace std;
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
struct IOSetup{
IOSetup(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(12);
}
} iosetup;
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
for(T &x:v)is>>x;
return is;
}
using Real=long double;
/*
dp[x] := 和xから和N以上にする期待値
dp[x] = 1 + p[1]*dp[x+1] + p[2]*dp[x+2] + p[3]*dp[x+3] + p[4]*dp[x+4] + p[5]*dp[x+5] + p[6]*dp[x+6]
if x >=N then dp[x] = 0
これを逆転する考察が良い
dp[x] := xからサイコロで引いていって,0以下にする期待値
dp[x] = 1 + p[1]*dp[x-1] + p[2]*dp[x-2] + p[3]*dp[x-3] + p[4]*dp[x-4] + p[5]*dp[x-5] + p[6]*dp[x-6]
if x <= 0 then dp[x] = 0
dp[2] = 1.0833333333333333
= 1 + p[1] * dp[1]
p[1] = 1.0833333333333333 - 1.0 = 0.0833333333333333
dp[3] = 1.2569444444444444
= 1 + p[1] * dp[2] + p[2] * dp[1]
p[2] = 0.2569444444444444 - p[1] * dp[2]
dp[4] = 1.5353009259259260
= 1 + p[1] * dp[3] + p[2] * dp[2] + p[3] * dp[1]
p[3] = dp[4] - 1 - p[1]*dp[3] - p[2]*dp[2]
*/
signed main(){
vector<Real> p(7);
vector<Real> dp(1010000);
dp[0]=0;
dp[1]=1.0000000000000000;
dp[2]=1.0833333333333333;
dp[3]=1.2569444444444444;
dp[4]=1.5353009259259260;
dp[5]=1.6915991512345676;
dp[6]=2.0513639724794235;
p[0]=0;
p[1]=0.0833333333333333;
p[2]=dp[3]-1-p[1]*dp[2];
p[3]=dp[4]-1-p[1]*dp[3]-p[2]*dp[2];
p[4]=dp[5]-1-p[1]*dp[4]-p[2]*dp[3]-p[3]*dp[2];
p[5]=dp[6]-1-p[1]*dp[5]-p[2]*dp[4]-p[3]*dp[3]-p[4]*dp[2];
p[6]=1-p[1]-p[2]-p[3]-p[4]-p[5];
for(int i=7;i<=1000100;i++){
dp[i]=1;
for(int j=1;j<=6;j++) dp[i]+=dp[i-j]*p[j];
}
int q;cin>>q;
while(q--){
int X;cin>>X;
cout<<dp[X]<<"\n";
}
return 0;
}
mugen_1337