結果

問題 No.75 回数の期待値の問題
ユーザー ciel
提出日時 2014-11-24 18:58:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 958 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 53,100 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-02 21:13:31
合計ジャッジ時間 1,503 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12 WA * 4
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |         scanf("%d",&N);
      |         ~~~~~^~~~~~~~~

ソースコード

diff #

#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;

//derived from checkio expected-dice
//unfortunately TLE using Python, rewriting in C++11.

double expected(int n, int s, int t){//vector<int> b){
	//perform checkio probably-dice
	vector<double> a(s*(n+1)+1);
	for(int i=1;i<=s;i++)a[i+s]=pow(1.0/s,n);
	for(int e=0;e<n-1;e++)for(int i=s*n;i>=0;i--){
		double sum=0;
		for(int j=i;j<i+s;j++)sum+=a[j];
		a[i+s]=sum;
	}
	int l=t+1; //b.size();
	double ret=0;
	vector<double> p(l);
	p[0]=1;
	//vector<int> nxt(l);
	//for(int i=0;i<l;i++)nxt[i]=(i+b[i]+l)%l;
	for(int z=1;z<400;z++){
		vector<double> pnxt(l);
		for(int x=0;x<l;x++)if(p[x]){
			for(int i=s+1;i<a.size();i++){
				int y=x+i-s;
				//y=nxt[y%l];
				if(y>=l)y=0;
				pnxt[y]+=p[x]*a[i];
			}
		}
		ret+=z*pnxt[t];
		pnxt[t]=0;
		p=pnxt;
	}
	return ret;
}

int main(){
	int N;
	scanf("%d",&N);
	printf("%f\n",expected(1,6,N));
}
0