diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2026-07-06 19:08:08 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2026-07-06 19:08:08 +0200 |
| commit | 96254947699986c59f0dc63d69fd4b76bd3ed43e (patch) | |
| tree | 6c4dca945d7f7427c48be234d827fe4d33be02c5 /12_interactive_problems/hidden_integer_3112.cpp | |
| download | cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.tar.gz cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.zip | |
Initial commit
Diffstat (limited to '')
| -rw-r--r-- | 12_interactive_problems/hidden_integer_3112.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/12_interactive_problems/hidden_integer_3112.cpp b/12_interactive_problems/hidden_integer_3112.cpp new file mode 100644 index 0000000..66e5a09 --- /dev/null +++ b/12_interactive_problems/hidden_integer_3112.cpp | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include <iostream> | ||
| 2 | #include <string> | ||
| 3 | |||
| 4 | int main() { | ||
| 5 | int m, l{0}, r{1000000000}; | ||
| 6 | std::string s; | ||
| 7 | while (l+1 != r) { | ||
| 8 | m = (l+r)/2; | ||
| 9 | std::cout << "? " << m << std::endl; | ||
| 10 | std::cin >> s; | ||
| 11 | if (s == "YES") l = m; | ||
| 12 | else r = m; | ||
| 13 | } | ||
| 14 | |||
| 15 | std::cout << "! " << r << std::endl; | ||
| 16 | } | ||
