結果

問題 No.58 イカサマなサイコロ
ユーザー 37zigen37zigen
提出日時 2016-05-04 19:57:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 5,000 ms
コード長 1,397 bytes
コンパイル時間 2,875 ms
コンパイル使用メモリ 77,488 KB
実行使用メモリ 54,232 KB
最終ジャッジ日時 2024-04-15 11:25:05
合計ジャッジ時間 4,561 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
54,232 KB
testcase_01 AC 139 ms
54,208 KB
testcase_02 AC 140 ms
54,088 KB
testcase_03 AC 141 ms
53,976 KB
testcase_04 AC 142 ms
54,096 KB
testcase_05 AC 143 ms
54,024 KB
testcase_06 AC 141 ms
54,232 KB
testcase_07 AC 141 ms
53,972 KB
testcase_08 AC 138 ms
53,992 KB
testcase_09 AC 141 ms
54,168 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