aboutsummaryrefslogtreecommitdiff
path: root/12_interactive_problems
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-07-06 19:08:08 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2026-07-06 19:08:08 +0200
commit96254947699986c59f0dc63d69fd4b76bd3ed43e (patch)
tree6c4dca945d7f7427c48be234d827fe4d33be02c5 /12_interactive_problems
downloadcses-96254947699986c59f0dc63d69fd4b76bd3ed43e.tar.gz
cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.zip
Initial commit
Diffstat (limited to '12_interactive_problems')
-rwxr-xr-x12_interactive_problems/a.outbin0 -> 14296 bytes
-rw-r--r--12_interactive_problems/hidden_integer_3112.cpp16
-rw-r--r--12_interactive_problems/hidden_permutation_3139.cpp45
3 files changed, 61 insertions, 0 deletions
diff --git a/12_interactive_problems/a.out b/12_interactive_problems/a.out
new file mode 100755
index 0000000..c949b8e
--- /dev/null
+++ b/12_interactive_problems/a.out
Binary files differ
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
4int 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}
diff --git a/12_interactive_problems/hidden_permutation_3139.cpp b/12_interactive_problems/hidden_permutation_3139.cpp
new file mode 100644
index 0000000..fc01d53
--- /dev/null
+++ b/12_interactive_problems/hidden_permutation_3139.cpp
@@ -0,0 +1,45 @@
1#include <iostream>
2#include <iterator>
3#include <string>
4#include <vector>
5
6void print_sol(const std::vector<size_t>& v) {
7 std::cout << "! ";
8 for (size_t i = 0; i < v.size(); i++) {
9 for (size_t j = 0; j < v.size(); j++) {
10 if (v[j] == i) {
11 std::cout << (j+1) << " ";
12 break;
13 }
14 }
15 }
16 std::cout << std::endl;
17}
18
19bool cmp(size_t i, size_t j) {
20 std::cout << "? " << (i+1) << " " << (j+1) << std::endl;
21 std::string s;
22 std::cin >> s;
23 return s == "YES";
24}
25
26size_t binsearch(size_t i, const std::vector<size_t>& v, size_t l, size_t r) {
27 if (r == l) return l;
28 size_t m = (l+r)/2;
29 return cmp(i, v[m]) ? binsearch(i, v, l, m) : binsearch(i, v, m+1, r);
30}
31
32int main() {
33 size_t n;
34 std::vector<size_t> v;
35 std::cin >> n;
36 v.reserve(n);
37
38 v.push_back(0);
39 for (size_t i = 1; i < n; i++) {
40 size_t pos = binsearch(i, v, 0, v.size());
41 v.insert(std::next(v.begin(), pos), i);
42 }
43
44 print_sol(v);
45}

Generated with cgit - Back to sebastiano.tronto.net