結果
問題 | No.58 イカサマなサイコロ |
ユーザー | threepipes_s |
提出日時 | 2015-12-30 18:27:34 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 48 ms / 5,000 ms |
コード長 | 3,383 bytes |
コンパイル時間 | 2,797 ms |
コンパイル使用メモリ | 89,544 KB |
実行使用メモリ | 37,240 KB |
最終ジャッジ日時 | 2024-09-19 08:47:54 |
合計ジャッジ時間 | 3,532 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashMap; public class Main { public static void main(String[] args) throws NumberFormatException, IOException {Solve solve = new Solve();solve.solve();} } class Solve{ void dump(int[]a){for(int i=0;i<a.length;i++) System.out.print(a[i]+" ");System.out.println();}; void solve() throws NumberFormatException, IOException{ final ContestScanner in = new ContestScanner(); Writer out = new Writer(); int n = in.nextInt(); int k = in.nextInt(); double[][] taro = new double[n][n*6]; double[][] jiro = new double[n][n*6]; for(int i=0; i<6; i++){ jiro[0][i] = 1/6.0; if(k<n) taro[0][i] = 1/6.0; else if(i>=3) taro[0][i] = 1/3.0; } int len = n*6; for(int i=1; i<n; i++){ for(int j=0; j<len-6; j++){ for(int d=1; d<=6; d++){ jiro[i][j+d] += jiro[i-1][j]/6; if(i<n-k) taro[i][j+d] += taro[i-1][j]/6; } if(i>=n-k){ for(int d=4; d<=6; d++){ taro[i][j+d] += taro[i-1][j]/3; } } } } double prob = 0; for(int i=0; i<len; i++){ for(int j=i+1; j<len; j++){ prob += jiro[n-1][i]*taro[n-1][j]; } } System.out.println(prob); } } class MultiSet<T> extends HashMap<T, Integer>{ @Override public Integer get(Object key){return containsKey(key)?super.get(key):0;} public void add(T key,int v){put(key,get(key)+v);} public void add(T key){put(key,get(key)+1);} public void sub(T key) {final int v=get(key);if(v==1)remove(key);else put(key,v-1);} } class Timer{ long time; public void set(){time=System.currentTimeMillis();} public long stop(){return time=System.currentTimeMillis()-time;} public void print() {System.out.println("Time: "+(System.currentTimeMillis()-time)+"ms");} @Override public String toString(){return"Time: "+time+"ms";} } class Writer extends PrintWriter{ public Writer(String filename)throws IOException {super(new BufferedWriter(new FileWriter(filename)));} public Writer()throws IOException{super(System.out);} } class ContestScanner { private InputStreamReader in;private int c=-2; public ContestScanner()throws IOException {in=new InputStreamReader(System.in);} public ContestScanner(String filename)throws IOException {in=new InputStreamReader(new FileInputStream(filename));} public String nextToken()throws IOException { StringBuilder sb=new StringBuilder(); while((c=in.read())!=-1&&Character.isWhitespace(c)); while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();} return sb.toString(); } public String readLine()throws IOException{ StringBuilder sb=new StringBuilder();if(c==-2)c=in.read(); while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();} return sb.toString(); } public long nextLong()throws IOException,NumberFormatException {return Long.parseLong(nextToken());} public int nextInt()throws NumberFormatException,IOException {return(int)nextLong();} public double nextDouble()throws NumberFormatException,IOException {return Double.parseDouble(nextToken());} }