Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include "cup.h"
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int MX_WORLD = 1000 * 1000 * 1000;
  6. int px,py, pRes;
  7.  
  8. int mod(int v){
  9.     return v>0 ? v: -v;
  10. }
  11.  
  12. void getPoint(int xDir, int yDir){
  13.     //printf("pX=%d, pY=%d, pRes=%d, %s\n", px, py, pRes, (xDir==1 ? "left" : "right"));
  14.     if(pRes == 0) return;
  15.     int change = pRes & -pRes;
  16.     int expectedRes = pRes & ~change;
  17.     int res = mod(px+ xDir*change) > MX_WORLD ? (1<<31 - 1) : ask_shahrasb(px + xDir*change, py);
  18.  
  19.     if(res == expectedRes){
  20.         px += xDir*change;
  21.         pRes = res;
  22.     } else {
  23.         py += yDir*change;
  24.         pRes = expectedRes;
  25.     }
  26.     getPoint(xDir, yDir);
  27. }
  28.  
  29.  
  30.  
  31. std::vector<int> find_cup() {
  32.     std::vector<int> result(2);
  33.     //bot left
  34.     px = py = -(int)(1e9);
  35.     pRes = ask_shahrasb(px, py);
  36.     getPoint(1,1);
  37.  
  38.     int blX = px, blY = py;
  39.  
  40.     px = (int)(1e9); py = -(int)(1e9);
  41.     pRes = ask_shahrasb(px, py);
  42.     getPoint(-1,1);
  43.     int brX = px, brY = py;
  44.  
  45.     int y = ((blY-blX) + (brY+brX))/2;
  46.     int x = ((brX + brY) - (blY-blX))/2;
  47.  
  48.     //printf("%d, %d\n%d, %d\n", blX, blY, brX, brY);
  49.  
  50.     result[0] = x;
  51.     result[1] = y;
  52.     return result;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement