Friday, April 5, 2019

[Toph] An Obvious Interactive Problem

Author            : Dipu Kumar Mohanto 
                    CSE, Batch - 6
                    BRUR.
Problem Statement : An Obvious Interactive Problem
Source            : Toph
Category          : Interactive Problems
Algorithm         : Interactive Problems, Binary Search
Verdict           : Accepted
  1. #include "bits/stdc++.h"  
  2.   
  3. using namespace std;  
  4.   
  5. int main()  
  6. {  
  7.       ios_base::sync_with_stdio(false);  
  8.       cin.tie(nullptr);  
  9.       cout << fixed << setprecision(2);  
  10.   
  11.       int lo = 0;  
  12.       int hi = 1000000;  
  13.       while (lo <= hi)  
  14.       {  
  15.             int mid = lo + hi >> 1;  
  16.             cout << mid << endl;  
  17.             fflush(stdout);  
  18.             string s;  
  19.             cin >> s;  
  20.             if (s == "Bigger") lo = mid + 1;  
  21.             else if (s == "Smaller") hi = mid - 1;  
  22.             else break;  
  23.       }  
  24. }  

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.