Problem Link
#include <iostream>
using namespace std;
int printIntermediateSteps(int s, int t, int i){
if(s > t){
return 0;
}
if(s == t){
return 1;
}
int mid = (s + t) / 2;
if(i <= mid){
cout << s << " " << mid << endl;
return printIntermediateSteps(s, mid, i) + 1;
}
else{
cout << (mid + 1) << " " << t << endl;
return printIntermediateSteps(mid + 1, t, i) + 1;
}
}
int main(){
int t, s, T, i, depth;
cin >> T;
while(T--){
cin >> s >> t >> i;
if(i < s || i > t){
cout << "-1";
continue;
}
depth = 1;
cout << s << " " << t << endl;
depth = printIntermediateSteps(s, t, i);
cout << depth << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int printIntermediateSteps(int s, int t, int i){
if(s > t){
return 0;
}
if(s == t){
return 1;
}
int mid = (s + t) / 2;
if(i <= mid){
cout << s << " " << mid << endl;
return printIntermediateSteps(s, mid, i) + 1;
}
else{
cout << (mid + 1) << " " << t << endl;
return printIntermediateSteps(mid + 1, t, i) + 1;
}
}
int main(){
int t, s, T, i, depth;
cin >> T;
while(T--){
cin >> s >> t >> i;
if(i < s || i > t){
cout << "-1";
continue;
}
depth = 1;
cout << s << " " << t << endl;
depth = printIntermediateSteps(s, t, i);
cout << depth << endl;
}
return 0;
}
Comments
Post a Comment