Advertisement
Josif_tepe

Untitled

Apr 3rd, 2023
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. //DON'T EDIT THIS FUNCTION, AS IT'S HERE TO SUPPORT
  6. //THE COMMUNICATION WITH THE INTERACTIVE GRADER
  7. int count(string expression) {
  8.     cout << expression << endl;
  9.    
  10.     int matchingRecords;
  11.     cin >> matchingRecords;
  12.     return matchingRecords;
  13. }
  14.  
  15.  
  16. //YOUR SOLUTION STARTS HERE
  17. string my_to_string(long long x) {
  18.     string res = "";
  19.     while(x > 0) {
  20.         res += ((x % 10) + '0');
  21.         x /= 10;
  22.     }
  23.     reverse(res.begin(), res.end());
  24.     return res;
  25. }
  26. int findMoney(int N) {
  27.     long long L = 0;
  28.     long long R = 2000000000;
  29.    
  30.     while(L <= R) {
  31.         long long middle = (L + R) / 2;
  32.         string is_less = "name != bidik || name == bidik && money < ";
  33.         is_less += my_to_string(middle);
  34.        
  35.         string is_equal = "name != bidik || name == bidik && money == ";
  36.         is_equal += my_to_string(middle);
  37.        
  38.         int less = count(is_less);
  39.         int equal = count(is_equal);
  40.        
  41.         if(equal == N) {
  42.             return middle;
  43.         }
  44.         if(less == N) {
  45.             R = middle;
  46.         }
  47.         else {
  48.             L = middle + 1;
  49.         }
  50.        
  51.     }
  52.     //make sure this function returns the money donated
  53.     return 0;
  54. }
  55.  
  56. int main(){
  57.     int n;
  58.     cin >> n;
  59.    
  60.     cout << findMoney(n) << endl;
  61.     return 0;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement