이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
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... |