結果

問題 No.76 回数の期待値で練習
ユーザー fura
提出日時 2020-06-11 03:02:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 582 bytes
コンパイル時間 2,877 ms
コンパイル使用メモリ 191,520 KB
最終ジャッジ日時 2025-01-11 01:06:12
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:28:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |         int q; scanf("%d",&q);
      |                ~~~~~^~~~~~~~~
main.cpp:30:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |                 int n; scanf("%d",&n);
      |                        ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	double a[5]={1.0833333333333333,
				 1.2569444444444444,
				 1.5353009259259260,
				 1.6915991512345676,
				 2.0513639724794235};

	double p[6];
	rep(i,5){
		p[i]=a[i]-1;
		rep(j,i) p[i]-=p[j]*a[i-j-1];
	}
	p[5]=1-p[0]-p[1]-p[2]-p[3]-p[4];

	double ans[1000001]={0,1};
	rep(i,5) ans[i+2]=a[i];
	for(int i=7;i<=1e6;i++){
		ans[i]=1;
		rep(d,6) ans[i]+=p[d]*ans[i-d-1];
	}

	int q; scanf("%d",&q);
	rep(_,q){
		int n; scanf("%d",&n);
		printf("%.9f\n",ans[n]);
	}

	return 0;
}
0