Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "cup.h"
- #include <bits/stdc++.h>
- using namespace std;
- const int MX_WORLD = 1000 * 1000 * 1000;
- int px,py, pRes;
- int mod(int v){
- return v>0 ? v: -v;
- }
- void getPoint(int xDir, int yDir){
- //printf("pX=%d, pY=%d, pRes=%d, %s\n", px, py, pRes, (xDir==1 ? "left" : "right"));
- if(pRes == 0) return;
- int change = pRes & -pRes;
- int expectedRes = pRes & ~change;
- int res = mod(px+ xDir*change) > MX_WORLD ? (1<<31 - 1) : ask_shahrasb(px + xDir*change, py);
- if(res == expectedRes){
- px += xDir*change;
- pRes = res;
- } else {
- py += yDir*change;
- pRes = expectedRes;
- }
- getPoint(xDir, yDir);
- }
- std::vector<int> find_cup() {
- std::vector<int> result(2);
- //bot left
- px = py = -(int)(1e9);
- pRes = ask_shahrasb(px, py);
- getPoint(1,1);
- int blX = px, blY = py;
- px = (int)(1e9); py = -(int)(1e9);
- pRes = ask_shahrasb(px, py);
- getPoint(-1,1);
- int brX = px, brY = py;
- int y = ((blY-blX) + (brY+brX))/2;
- int x = ((brX + brY) - (blY-blX))/2;
- //printf("%d, %d\n%d, %d\n", blX, blY, brX, brY);
- result[0] = x;
- result[1] = y;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement