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; } } }