結果

問題 No.301 サイコロで確率問題 (1)
ユーザー ぴろずぴろず
提出日時 2015-11-13 23:27:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 120 ms / 1,000 ms
コード長 13,412 bytes
コンパイル時間 4,781 ms
コンパイル使用メモリ 77,552 KB
実行使用メモリ 52,904 KB
最終ジャッジ日時 2023-10-11 16:44:45
合計ジャッジ時間 5,182 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

package no301;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;


public class Main {
	static double[] evil = {-1,5.999999999999995,5.999999999999995,5.999999999999995,5.9999999999999964,5.999999999999997,5.999999999999998,9.943149324581292,10.3517072141596,10.854714237226819,11.489202567069013,12.314474731492902,13.431807062589353,15.029569384604738,15.787804576056313,16.636758444529896,17.577932816676682,18.601876299228614,19.67842048838053,20.741892080344904,21.67275327051826,22.645249282849854,23.647260743078604,24.663472996803872,25.677644130712828,26.67746871641907,27.663148638279985,28.661031704745536,29.664477440702754,30.66819883794905,31.669210209817784,32.667421919772465,33.66530884752892,34.66576002113656,35.666740700155174,36.66720695592579,37.667003915939375,38.66655495314066,39.66637950093471,40.666595053333644,41.666762332170535,42.66676664509686,43.666679251331274,44.66661508522843,45.666626921597185,46.666675435812905,47.666691138983225,48.66667728007157,49.66665994236874,50.666656208321854,51.66666413629016,52.66667128948619,53.66667049477368,54.66666654879625,55.666664502994294,56.66666537022745,57.66666710817701,58.66666767059864,59.66666698728554,60.66666632645452,61.66666628465245,62.66666661893563,63.66666685276236,64.6666668050259,65.66666664355068,66.66666657954045,67.66666662658851,68.66666669004694,69.66666670322269,70.66666667555916,71.66666665164564,72.66666665313858,73.66666666669292,74.66666667406841,75.66666667113384,76.66666666524833,77.66666666335966,78.6666666655027,79.66666666776189,80.666666667957,81.66666666684293,82.66666666606162,83.66666666620952,84.66666666672731,85.66666666694957,86.66666666680231,87.66666666659316,88.66666666654797,89.6666666666359,90.6666666667129,91.66666666671028,92.66666666666711,93.66666666664281,94.66666666665171,95.66666666667038,96.66666666667658,97.6666666666701,98.66666666666288,99.66666666666208,100.66666666666552,101.66666666666798,102.66666666666754,103.6666666666659,104.66666666666517,105.6666666666656,106.66666666666626,107.66666666666642,108.66666666666615,109.66666666666586,110.66666666666586,111.666666666666,112.66666666666609,113.66666666666605,114.66666666666596,115.66666666666593,116.66666666666593,117.66666666666592,118.66666666666586,119.6666666666658,120.66666666666578,121.6666666666658,122.66666666666578,123.66666666666575,124.66666666666575,125.66666666666573,126.6666666666657,127.66666666666572,128.6666666666657,129.66666666666566,130.66666666666566,131.66666666666563,132.66666666666566,133.66666666666566,134.66666666666563,135.66666666666563,136.6666666666656,137.6666666666656,138.6666666666656,139.6666666666656,140.6666666666656,141.6666666666656,142.6666666666656,143.6666666666656,144.66666666666555,145.66666666666558,146.66666666666555,147.66666666666555,148.66666666666555,149.66666666666555,150.66666666666555,151.66666666666555,152.66666666666552,153.6666666666655,154.66666666666555,155.6666666666655,156.6666666666655,157.6666666666655,158.6666666666655,159.6666666666655,160.6666666666655,161.66666666666544,162.66666666666546,163.66666666666544,164.66666666666544,165.66666666666546,166.66666666666544,167.66666666666544,168.66666666666544,169.66666666666544,170.66666666666544,171.66666666666538,172.66666666666538,173.66666666666538,174.6666666666654,175.66666666666538,176.66666666666538,177.66666666666538,178.66666666666535,179.66666666666532,180.66666666666538,181.66666666666535,182.66666666666532,183.66666666666532,184.66666666666532,185.66666666666532,186.6666666666653,187.66666666666532,188.66666666666526,189.66666666666526,190.66666666666526,191.66666666666526,192.6666666666653,193.66666666666526,194.66666666666526,195.66666666666526,196.66666666666524,197.66666666666524,198.66666666666526,199.66666666666526,200.6666666666652,201.6666666666652,202.6666666666652,203.6666666666652,204.6666666666652,205.66666666666518,206.6666666666652,207.6666666666652,208.66666666666518,209.66666666666515,210.66666666666515,211.66666666666515,212.66666666666515,213.66666666666515,214.66666666666512,215.6666666666651,216.66666666666512,217.66666666666512,218.6666666666651,219.6666666666651,220.6666666666651,221.66666666666512,222.6666666666651,223.6666666666651,224.6666666666651,225.6666666666651,226.6666666666651,227.66666666666507,228.66666666666504,229.66666666666507,230.66666666666507,231.6666666666651,232.66666666666512,233.6666666666651,234.6666666666651,235.6666666666651,236.6666666666651,237.6666666666651,238.6666666666651,239.66666666666512,240.6666666666651,241.66666666666512,242.66666666666512,243.66666666666512,244.66666666666515,245.66666666666515,246.66666666666515,247.66666666666515,248.66666666666515,249.66666666666515,250.6666666666652,251.66666666666515,252.66666666666515,253.6666666666652,254.6666666666652,255.66666666666518,256.66666666666515,257.66666666666515,258.6666666666652,259.6666666666652,260.6666666666652,261.6666666666652,262.66666666666515,263.6666666666652,264.6666666666652,265.6666666666652,266.66666666666526,267.66666666666526,268.66666666666526,269.66666666666526,270.66666666666526,271.66666666666526,272.66666666666526,273.66666666666526,274.6666666666653,275.66666666666526,276.66666666666526,277.66666666666526,278.6666666666653,279.66666666666526,280.6666666666653,281.66666666666526,282.6666666666654,283.66666666666526,284.6666666666654,285.6666666666653,286.66666666666526,287.6666666666653,288.6666666666653,289.66666666666526,290.6666666666654,291.6666666666653,292.6666666666653,293.6666666666654,294.6666666666654,295.6666666666654,296.6666666666654,297.6666666666654,298.6666666666654,299.6666666666654,300.6666666666654,301.6666666666654,302.6666666666654,303.66666666666544,304.6666666666654,305.6666666666654,306.6666666666654,307.6666666666654,308.6666666666654,309.6666666666654,310.6666666666654,311.6666666666655,312.66666666666544,313.66666666666544,314.6666666666655,315.66666666666544,316.6666666666654,317.66666666666544,318.6666666666655,319.6666666666655,320.6666666666655,321.6666666666655,322.6666666666655,323.6666666666655,324.6666666666655,325.6666666666655,326.6666666666655,327.6666666666655,328.6666666666655,329.6666666666655,330.6666666666655,331.6666666666655,332.6666666666655,333.6666666666655,334.6666666666655,335.6666666666655,336.6666666666656,337.66666666666555,338.66666666666555,339.6666666666656,340.66666666666555,341.6666666666656,342.6666666666656,343.6666666666656,344.6666666666656,345.6666666666656,346.6666666666656,347.6666666666656,348.6666666666656,349.6666666666656,350.6666666666656,351.6666666666656,352.6666666666656,353.6666666666656,354.66666666666566,355.66666666666566,356.6666666666656,357.6666666666656,358.66666666666566,359.6666666666656,360.6666666666656,361.6666666666657,362.66666666666566,363.6666666666656,364.6666666666657,365.66666666666566,366.66666666666566,367.6666666666656,368.6666666666657,369.6666666666657,370.6666666666657,371.6666666666657,372.6666666666657,373.6666666666657,374.6666666666657,375.6666666666658,376.6666666666657,377.6666666666657,378.6666666666657,379.6666666666657,380.6666666666657,381.6666666666657,382.66666666666583,383.6666666666657,384.6666666666657,385.6666666666658,386.66666666666583,387.6666666666658,388.6666666666657,389.6666666666658,390.66666666666583,391.66666666666583,392.6666666666658,393.66666666666583,394.6666666666658,395.66666666666583,396.66666666666583,397.66666666666583,398.66666666666583,399.6666666666659,400.66666666666583,401.66666666666583,};
	public static void main(String[] args) {
		IO io = new IO();
		int t = io.nextInt();
		for(int i=0;i<t;i++) {
			long n = io.nextLong();
			if (n <= 400) {
				io.println(evil[(int) n]);
			}else{
				io.println(n + 1 + 2D / 3);
			}
		}
		io.flush();
	}

	public static double solve75(int k) {
		double[][] a = new double[k+1][k+1];
		double[] b = new double[k+1];
		for(int i=0;i<k;i++) {
			a[i][i] = 1;
			b[i] = 1;
			for(int j=1;j<=6;j++) {
				if (i + j <= k) {
					a[i][i+j] -= 1D / 6;
				}else{
					a[i][0] -= 1D / 6;
				}
			}
		}
		a[k][k] = 1;
		double[] x = Matrix.solveEquation(a, b);
		return x[0];
	}
}
class IO extends PrintWriter {
	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	public IO() { this(System.in);}
	public IO(InputStream source) { super(System.out); this.in = source;}
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	private static boolean isNewLine(int c) { return c == '\n' || c == '\r';}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public boolean hasNextLine() { while(hasNextByte() && isNewLine(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public char[] nextCharArray(int len) {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		char[] s = new char[len];
		int i = 0;
		int b = readByte();
		while(isPrintableChar(b)) {
			if (i == len) {
				throw new InputMismatchException();
			}
			s[i++] = (char) b;
			b = readByte();
		}
		return s;
	}
	public String nextLine() {
		if (!hasNextLine()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(!isNewLine(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public char nextChar() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		return (char) readByte();
	}
	public double nextDouble() { return Double.parseDouble(next());}
	public int[] nextIntArray(int n) { int[] a = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a;}
	public long[] nextLongArray(int n) { long[] a = new long[n]; for(int i=0;i<n;i++) a[i] = nextLong(); return a;}
	public double[] nextDoubleArray(int n) { double[] a = new double[n]; for(int i=0;i<n;i++) a[i] = nextDouble(); return a;}
	public void nextIntArrays(int[]... a) { for(int i=0;i<a[0].length;i++) for(int j=0;j<a.length;j++) a[j][i] = nextInt();}
	public int[][] nextIntMatrix(int n,int m) { int[][] a = new int[n][]; for(int i=0;i<n;i++) a[i] = nextIntArray(m); return a;}
	public char[][] nextCharMap(int n,int m) { char[][] a = new char[n][]; for(int i=0;i<n;i++) a[i] = nextCharArray(m); return a;}
	public void close() { super.close(); try {in.close();} catch (IOException e) {}}
}


class Matrix {
	public static final double EPS = 1E-8;
	public static double[][] add(double[][] a,double[][] b) {
		int n = a.length;
		int m = a[0].length;
		double[][] c = new double[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				c[i][j] = a[i][j] + b[i][j];
			}
		}
		return c;
	}
	public static double[][] muliply(double[][] a,double k) {
		int n = a.length;
		int m = a[0].length;
		double[][] c = new double[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				c[i][j] = a[i][j] * k;
			}
		}
		return c;
	}
	public static double[][] muliply(double[][] a,double[][] b) {
		int n = a.length;
		int m = b[0].length;
		double[][] c = new double[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				for(int k=0;k<n;k++) {
					c[i][j] += a[i][k] * b[k][j];
				}
			}
		}
		return c;
	}
	//disruptive
	public static double[] solveEquation(double[][] A,double[] b) {
		int n = A.length;
		double[][] B = new double[n][n+1];
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				B[i][j] = A[i][j];
			}
			B[i][n] = b[i];
		}
		for(int i=0;i<n;i++) {
			int pivot = i;
			for(int j=i;j<n;j++) {
				if (Math.abs(B[j][i]) > Math.abs(B[pivot][i])) {
					pivot = j;
				}

			}
			swapRow(B, i, pivot);
			if (Math.abs(B[i][i]) < EPS) {
				return null;
			}
			for(int j=i+1;j<=n;j++) {
				B[i][j] /= B[i][i];
			}
			for(int j=0;j<n;j++) {
				if (i==j) {
					continue;
				}
				for(int k=i+1;k<=n;k++) {
					B[j][k] -= B[j][i] * B[i][k];
				}
			}
		}
		double[] x = new double[n];
		for(int i=0;i<n;i++) {
			x[i] = B[i][n];
		}
		return x;
	}
	public static void swapRow(double[][] A,int i,int j) {
		double[] temp = A[i];
		A[i] = A[j];
		A[j] = temp;
	}
}
0