-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF_1486C1.cpp
More file actions
72 lines (60 loc) · 841 Bytes
/
CF_1486C1.cpp
File metadata and controls
72 lines (60 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int l = 1, r = n;
int second;
while (l < r)
{
cout << "? " << l << ' ' << r << endl;
cout.flush();
cin >> second;
if (r - l <= 1)
{
break;
}
int mid = (r + l) / 2;
if (mid < second)
{
int right;
cout << "? " << mid << ' ' << r << endl;
cout.flush();
cin >> right;
// 최대값은 오른쪽에 있음.
if (right == second)
{
l = mid;
}
else
{
r = mid;
}
}
else
{
int left;
cout << "? " << l << ' ' << mid << endl;
cout.flush();
cin >> left;
// 최대값은 왼쪽에 있음.
if (left == second)
{
r = mid;
}
else
{
l = mid;
}
}
}
if (l == second)
{
cout << "! " << r << endl;
}
else
{
cout << "! " << l << endl;
}
cout.flush();
}