1 solutions
-
0
本题是 OJ 的第一道交互题
此题起到一个提示作用,当作模板。
C/C++ 示例代码如下:
#include <bits/stdc++.h> using namespace std; int query(int a) { cout << "? " << a << endl; int x; cin >> x; return x; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int l = 1, r = 1000000000; int ans = 0; while (l <= r) { int mid = (l + r) / 2; int t = query(mid); if (t == 1) { r = mid - 1; } else if (t == -1) { l = mid + 1; } else { ans = mid; break; } } cout << "! " << ans << endl; return 0; }
- 1
Information
- ID
- 353
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 11
- Accepted
- 3
- Uploaded By