#include<bits/stdc++.h>usingnamespace std;
intmain()
{
int n,c;
cin >> n >>c;
int lo =0, hi = n, res =0;
while(hi-lo >1){
if(res)cout <<2<<endl<<flush;
int mid = lo + (hi-lo-1)/8+1;
cout <<1<<" "<<mid<<endl<<flush;
cin >> res;
if(res)hi = mid;
else lo = mid;
}
cout <<3<<" "<<hi<<endl<<flush;
return0;
}
Solution 02:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<bits/stdc++.h>usingnamespace std;
intmain()
{
int n,c;
cin >> n >>c;
int lo =1, hi = n+1, res =0;
while(hi-lo >1){
if(res)cout <<2<<endl<<flush;
int mid = lo + (hi-lo)/60;
cout <<1<<" "<<mid<<endl<<flush;
cin >> res;
if(res)hi = mid+1;
else lo = mid+1;
}
cout <<3<<" "<<lo<<endl<<flush;
return0;
}
#include<bits/stdc++.h>usingnamespace std;
boolsolve(int x)
{
cout <<"1 "<<x<<endl<<flush;
int a;
cin >> a;
return a;
}
intmain()
{
int n,c;
cin >> n >>c;
int ans =-1, lg =0, le =-1;
int range = sqrt(n);
//cout << range<<endl;for(int i =1; i <= n; i += range){
// cout << i << endl;if(solve(i)){
ans = i;
break;
}
lg = i;
le = min(i+range-1, n);
}
cout <<2<<endl<<flush;
for(int i = lg; i <= le; i++){
if(solve(i)){
ans = i;
break;
}
}
cout <<3<<" "<<ans<<endl<<flush;
return0;
}
No comments:
Post a Comment