提出詳細


ソースコード

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class ProbabilityCalculator {

	public double getDrawCardProbability(double deckNum, double drawNum, double targetCardNum) {
		if(deckNum == drawNum && targetCardNum > 0) return 1;
		
		boolean isMajority = (deckNum / 2 > drawNum) ;
		double searchNum = isMajority ? drawNum : deckNum - drawNum;
		 
		double neverDrawP = (deckNum - targetCardNum) / deckNum;

		for (int i = 1; i < searchNum; i++) {
			neverDrawP *= (deckNum - targetCardNum - i) / (deckNum - i);
		}

		double drawP = (1 - neverDrawP);

		return drawP;

	}

	public static void main(String[] args) {
		// // TODO Auto-generated method stub
		
		File inFile = new File("D.txt");
		BufferedReader reader = null;
		FileReader fr = null;
		File outFile = new File("result.txt");
		BufferedWriter writer = null;
		FileWriter fw = null;
		try {
			// リーダ生成
			fr = new FileReader(inFile);
			reader = new BufferedReader(fr);
			// ライター生成
			fw = new FileWriter(outFile);
			writer = new BufferedWriter(fw);

			// テストケース数を読み込み
			int testCaseNum = Integer.parseInt(reader.readLine());

			// テストケース毎に計算、出力
			for (int i = 1; i <= testCaseNum; i++) {
				String caseNumStr = "Case #" + i + ":";

				String[] inputs = reader.readLine().split(" ");

				int deckNum = Integer.parseInt(inputs[0]);
				int drawNum = Integer.parseInt(inputs[1]);
				int thresholdP = Integer.parseInt(inputs[2]);
				
				ProbabilityCalculator calculator = new ProbabilityCalculator();

				int p = 0;
				int targetCardNum = 0;
				for (int cardNum = 1; cardNum <= deckNum; cardNum++) {
					p = (int)(calculator.getDrawCardProbability(deckNum, drawNum, cardNum) * 100);
					if(p >= thresholdP) {
						targetCardNum = cardNum;
						break;
					}
				}
					

				// 標準出力
				System.out.println(caseNumStr);
				System.out.println(targetCardNum);

				// テキストファイルとして書き込み処理
				writer.write(caseNumStr);
				writer.newLine();
				writer.write(targetCardNum);
				writer.newLine();
			}
			// テキストファイルをフラッシュ
			writer.flush();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			// 各IOインスタンスのクローズ処理
			try {
				if (reader != null)
					reader.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				if (reader != null)
					writer.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				if (fr != null)
					fr.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				if (reader != null)
					fw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}

提出情報

提出時間 2018-07-01 22:48:30
問題 D - 計算しつくされた運命
ユーザ名 soutarou1210
状態 不正解
正解率 0/51
提出出力結果

テストケース情報

# 状態 詳細情報
テストケース 1 不正解 詳細を見る
テストケース 2 不正解 詳細を見る
テストケース 3 不正解 詳細を見る
テストケース 4 不正解 詳細を見る
テストケース 5 不正解 詳細を見る
テストケース 6 不正解 詳細を見る
テストケース 7 不正解 詳細を見る
テストケース 8 不正解 詳細を見る
テストケース 9 不正解 詳細を見る
テストケース 10 不正解 詳細を見る
テストケース 11 不正解 詳細を見る
テストケース 12 不正解 詳細を見る
テストケース 13 不正解 詳細を見る
テストケース 14 不正解 詳細を見る
テストケース 15 不正解 詳細を見る
テストケース 16 不正解 詳細を見る
テストケース 17 不正解 詳細を見る
テストケース 18 不正解 詳細を見る
テストケース 19 不正解 詳細を見る
テストケース 20 不正解 詳細を見る
テストケース 21 不正解 詳細を見る
テストケース 22 不正解 詳細を見る
テストケース 23 不正解 詳細を見る
テストケース 24 不正解 詳細を見る
テストケース 25 不正解 詳細を見る
テストケース 26 不正解 詳細を見る
テストケース 27 不正解 詳細を見る
テストケース 28 不正解 詳細を見る
テストケース 29 不正解 詳細を見る
テストケース 30 不正解 詳細を見る
テストケース 31 不正解 詳細を見る
テストケース 32 不正解 詳細を見る
テストケース 33 不正解 詳細を見る
テストケース 34 不正解 詳細を見る
テストケース 35 不正解 詳細を見る
テストケース 36 不正解 詳細を見る
テストケース 37 不正解 詳細を見る
テストケース 38 不正解 詳細を見る
テストケース 39 不正解 詳細を見る
テストケース 40 不正解 詳細を見る
テストケース 41 不正解 詳細を見る
テストケース 42 不正解 詳細を見る
テストケース 43 不正解 詳細を見る
テストケース 44 不正解 詳細を見る
テストケース 45 不正解 詳細を見る
テストケース 46 不正解 詳細を見る
テストケース 47 不正解 詳細を見る
テストケース 48 不正解 詳細を見る
テストケース 49 不正解 詳細を見る
テストケース 50 不正解 詳細を見る
テストケース 51 不正解 詳細を見る