Advertisement
Guest User

Untitled

a guest
Jul 13th, 2018
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long double ld;
  5. typedef int64_t ll;
  6.  
  7. int ask (ll x, ll y) {
  8.     cout << x << ' ' << y << endl;
  9.     int res;
  10.     cin >> res;
  11.     return res;
  12. }
  13.  
  14. int main () {
  15.     ll n;
  16.     cin >> n;
  17.     ll x0 = 1, x1 = n + 1, x2 = n + 1;
  18.     ll y0 = 1, y1 = n + 1, y2 = n + 1;
  19.    
  20.     while (1) {
  21.         ld s00 = ld(x1 - x0) * ld(y1 - y0);
  22.         ld s10 = ld(x2 - x1) * ld(y1 - y0);
  23.         ld s01 = ld(x1 - x0) * ld(y2 - y1);
  24.         ll x = (x0 + x1) / 2;
  25.         ll y = (y0 + y1) / 2;
  26.         if (s10 > s00 + s01) {
  27.             x = x1;
  28.         }
  29.         if (s01 > s00 + s10) {
  30.             y = y1;
  31.         }
  32.         int res = ask(x, y);
  33.         if (res == 1) {
  34.             x0 = x + 1;
  35.         } else if (res == 2) {
  36.             y0 = y + 1;
  37.         } else if (res == 3) {
  38.             x1 = x;
  39.             y1 = y;
  40.         } else {
  41.             break;
  42.         }
  43.         if (x1 <= x0) {
  44.             x1 = x2;
  45.             y2 = y1;
  46.         }
  47.         if (y1 <= y0) {
  48.             y1 = y2;
  49.             x2 = x1;
  50.         }
  51.     }
  52.    
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement