結果

問題 No.246 質問と回答
ユーザー kenji_shioya
提出日時 2016-06-16 21:50:26
言語 Java
(openjdk 23)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 3,925 ms
コンパイル使用メモリ 76,140 KB
実行使用メモリ 71,272 KB
平均クエリ数 30.90
最終ジャッジ日時 2024-07-16 20:04:47
合計ジャッジ時間 12,035 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise90{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    int head = 1;
    int tail = 1000000000;
    int center = 0;
    while(true){
      center = (tail - head) / 2 + head;
      if(tail - head < 2){
        break;
      }
      System.out.println("? " + center);
      System.out.flush();

      int answer = sc.nextInt();
      
      if(answer == 0){
        tail = center;
      }else{
        head = center;
      }
    }
    System.out.println("! " + center);
  }
}
0