結果

問題 No.76 回数の期待値で練習
ユーザー ohuton_laboohuton_labo
提出日時 2014-12-12 01:06:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 1,232 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 64,376 KB
実行使用メモリ 11,476 KB
最終ジャッジ日時 2023-09-02 14:16:23
合計ジャッジ時間 909 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
11,348 KB
testcase_01 AC 17 ms
11,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <stdlib.h>



using namespace std;

/*
cin.ignore();
	getline(cin,dataStr);
	data = new int[n];
	stringToInteger(&dataStr,data,n);
*/

void stringToInteger(string *str,int *data,int n){
	for(int i=0;i<n;i++){
		int spaceN = str->find(' ',0);

		data[i] = atoi(str->substr(0,spaceN).c_str());
		str->erase(0,spaceN+1);
	}
}

void dPrint(double *a,int n){
	for(int i=0;i<n;i++){
		cout<<a[i]<<endl;
	}
	cout<<endl;
}

//dp[i] i:iが出るまでに振る回数の期待値
double dp[1000010];

int main(){

	dp[1] = 1.0000000000000000;
	dp[2] = 1.0833333333333333;
	dp[3] = 1.2569444444444444;
	dp[4] = 1.5353009259259260;
	dp[5] = 1.6915991512345676;
	dp[6] = 2.0513639724794235;

	double p[7];

	p[1]=1.0/12.0;
	p[2]=2.0/12.0;
	p[3]=3.0/12.0;
	p[4]=1.0/12.0;
	p[5]=3.0/12.0;
	p[6]=2.0/12.0;
	

	for(int i=7;i<=1000000;i++){
		for(int j=i-6;j<i;j++){
			//cout<<j<<" "<<dp[j]<<" "<<p[i-j]<<endl;
			dp[i]+=dp[j]*p[i-j];
		}
		dp[i]+=1;
	}
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
		int num;
		cin>>num;
		cout<<dp[num]<<endl;
	}

	return 0;
}
0