結果

問題 No.58 イカサマなサイコロ
ユーザー 37zigen37zigen
提出日時 2016-05-04 19:57:45
言語 Java19
(openjdk 21)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 1,397 bytes
コンパイル時間 3,911 ms
コンパイル使用メモリ 79,448 KB
実行使用メモリ 56,476 KB
最終ジャッジ日時 2023-07-28 01:25:12
合計ジャッジ時間 4,601 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,476 KB
testcase_01 AC 119 ms
55,916 KB
testcase_02 AC 118 ms
55,896 KB
testcase_03 AC 120 ms
56,112 KB
testcase_04 AC 120 ms
56,188 KB
testcase_05 AC 119 ms
56,108 KB
testcase_06 AC 120 ms
56,116 KB
testcase_07 AC 117 ms
55,528 KB
testcase_08 AC 117 ms
55,928 KB
testcase_09 AC 118 ms
56,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args)throws Exception{
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		//1<=n<=10
		
		int k=sc.nextInt();
		//0<=k<=n 回イカサマさいころを用いる。
		
		double[][] e=new double[11][61];
		e[0][0]=1;
		/*e[i][j]=i回さいころを振ったとき(イカサマさいころk回、普通のさいころn-k回)、
		 * 出た目の合計がjである確率。
		 */
		
		double[][] e1=new double[11][61];
		e1[0][0]=1;
		//普通のさいころをn回振った時の確率
		
		
		//普通のさいころをn-k回振る。
		for(int i=1;i<=n-k;i++){
			for(int j=0;j<61;j++){
				for(int l=1;l<=6;l++){
					if(j-l>=0)e[i][j]+=e[i-1][j-l]*(1.0/6.0);
				}
			}
		}
		//イカサマさいころをk回振る。
		for(int i=n-k+1;i<=n;i++){
			for(int j=0;j<61;j++){
				for(int l=4;l<=6;l++){
					if(j-l>=0)e[i][j]+=e[i-1][j-l]*(1.0/3.0);
				}
			}
		}
		
		for(int i=1;i<=n;i++){
			for(int j=0;j<61;j++){
				for(int l=1;l<=6;l++){
					if(j-l>=0)e1[i][j]+=e1[i-1][j-l]*(1.0/6.0);
				}
			}
		}

		double p=0;//勝つ確率
		for(int i=0;i<61;i++){
			for(int j=i-1;j>=0;j--)
				p+=e[n][i]*e1[n][j];
		}
		System.out.println(p);
		
	}
	
	void tr(Object...o){System.out.println(Arrays.deepToString(o));}
}
0