This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.io.*;
import java.util.*;
public class Guess {
static class Tokenizer extends StreamTokenizer {
public Tokenizer(Reader r) {
super(r);
resetSyntax();
whitespaceChars(0, ' ');
wordChars(' '+1, 127);
parseNumbers();
}
public int nextInt() throws IOException {
return (int)nextDouble();
}
public long nextLong() throws IOException {
return (long)nextDouble(); // Up to +/- 10^15
}
public double nextDouble() throws IOException {
nextToken();
return nval;
}
public String nextString() throws IOException {
nextToken();
return sval;
}
}
public static void main(String[] args) throws IOException {
Tokenizer in = new Tokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int a = 1, b = in.nextInt();
while (a < b) {
int m = (a + b) / 2;
out.print("? ");
out.println(m);
out.flush();
int ans = in.nextInt();
if (ans < 0) {
a = m + 1;
} else if (ans > 0) {
b = m - 1;
} else {
a = b = m;
}
}
out.print("= ");
out.println(a);
out.close();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |