結果
| 問題 |
No.63 ポッキーゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-09 08:50:03 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 5,000 ms |
| コード長 | 2,307 bytes |
| コンパイル時間 | 3,496 ms |
| コンパイル使用メモリ | 76,840 KB |
| 実行使用メモリ | 37,132 KB |
| 最終ジャッジ日時 | 2024-12-24 05:31:55 |
| 合計ジャッジ時間 | 5,326 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
package test6;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* No.63 ポッキーゲーム http://yukicoder.me/problems/no/63
* 長さが L(mm)のポッキーを2人はそれぞれ両端から中央に向かって齧っていきます。
* 2人とも毎回 K(mm) ずつ同じタイミングでポッキーを齧ります。
* ユウちゃんは恥ずかしがり屋さんなので、
* 次のタイミングで2人ともポッキーを齧ろうとしたら唇が触れてしまうと分かった時点で齧り進めるのを止めて、
* 残りは全部ハルカちゃんが食べてしまいます。
*/
public class Question_15_0609_1 {
static final int POKI_MIN = 1;
static final int EAT_MIN = 1;
static final int POKI_MAX = (int)Math.pow(10, 9);
static final int EAT_MAX = 50;
public static void main(String[] args) {
InputStreamReader re = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(re);
try {
String[] input = br.readLine().split(" ");
int pokyLneth = Integer.parseInt(input[0]);
int eatLneth = Integer.parseInt(input[1]);
//有効値確認
if (NumJudg(pokyLneth, POKI_MIN, POKI_MAX)
&& NumJudg(eatLneth, EAT_MIN, EAT_MAX)) {
int center = pokyLneth / 2;
int touchCount = center / eatLneth;
//touchCountが0でない、かつ触れる場合はマイナス1する
if (touchCount != 0 && touchCount * eatLneth * 2 == pokyLneth) {
touchCount--;
}
System.out.println(touchCount * eatLneth);
}
} catch (NumberFormatException e) {
System.out.println("数字を入力して下さい。");
} catch (IOException e) {
System.out.println("エラーが発生しました。");
} finally {
try {
re.close();
br.close();
} catch (IOException e) {
System.out.println("InputStreamReader、BufferedReaderクローズ中にエラーが発生しました");
}
}
}
/**
* 有効値判定
* @param input 判定するもの
* @param max 最大値
* @param min 最小値
* @return 範囲内ならtrue,範囲外ならfalseを返す
*/
private static boolean NumJudg(int input, int min, int max) {
Boolean result = false;
if (min <= input && input <= max) {
result = true;
}
return result;
}
}