-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQHOUSE.cpp
More file actions
63 lines (58 loc) · 1.38 KB
/
Copy pathQHOUSE.cpp
File metadata and controls
63 lines (58 loc) · 1.38 KB
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
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
string response;
int squareBaseSearch(int low, int high){
while(low<high){
int mid = low + (high-low)/2;
cout<<"? "<<mid<<" "<<0<<"\n";
fflush(stdout);
cin>>response;
if(response == "YES"){
low = mid+1;
}
else {
high = mid;
}
}
return low-1;
}
int triangeHeightSearch(int low, int high){
while(low<high){
int mid = low + (high-low)/2;
cout<<"? "<<0<<" "<<mid<<"\n";
fflush(stdout);
cin>>response;
if(response == "YES"){
low = mid+1;
}
else {
high = mid;
}
}
return low-1;
}
int triangleBaseSearch(int low, int high, int y){
while(low<high){
int mid = low + (high-low)/2;
cout<<"? "<<mid<<" "<<y<<"\n";
fflush(stdout);
cin>>response;
if(response == "YES"){
low = mid+1;
}
else {
high = mid;
}
}
return low-1;
}
int main() {
int squareBase = squareBaseSearch(1, 1001);
int triangeHeight = triangeHeightSearch(2*squareBase, 1001);
int triangleBase = triangleBaseSearch(squareBase, 1001, 2*squareBase);
int S = (4*squareBase*squareBase)+(triangleBase*(triangeHeight-(2*squareBase)));
cout<<"! "<<S;
return 0;
}