結果

問題 No.253 ロウソクの長さ
ユーザー Kilisame
提出日時 2016-09-30 16:02:08
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 962 bytes
コンパイル時間 3,333 ms
コンパイル使用メモリ 75,960 KB
実行使用メモリ 71,180 KB
平均クエリ数 23.11
最終ジャッジ日時 2024-07-16 11:07:44
合計ジャッジ時間 11,797 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

package puzzle.yukicoder.lengthofcandle;

import java.util.Scanner;

public class Lengthofcandle {

    public static void main(String[] args) {
        int min = 10;
        int max = 1000000000;
        int current = 100;
        Scanner cin = new Scanner(System.in);
        for (int i = 0; i < 100; i++) {
            /* 単純に2分探索したい。しかし、長さが100以下の場合、途中で燃え尽きてしまうため、探索の開始は100とする */
            System.out.println("? " + (current - i));
            System.out.flush();
            String result = cin.nextLine();
            if (result.equals("0")) {
                System.out.println("! " + current);
                System.out.flush();
                System.exit(0);
            } else if (result.equals("1")) {
                min = current;
            } else {
                max = current;
            }
            current = (min + max) / 2;
        }
    }

}
0