Yuki 514 宝探し3 ( Ad hoc, Interactive )
題意:
在一個 1e9 * 1e9 的平面上,有個座標藏著寶藏。你每次可以問一個點和寶藏的曼哈頓距離是多少。請在兩次以內的詢問找到寶藏位置。
解法:
問 ( 0, 0 ) 得距離 A,接著問 ( 0, A ) 得距離 B,那麼寶藏一定在 ( B / 2, A - B / 2 )
#include <bits/stdc++.h> using namespace std; int ask( int x, int y ) { cout << x << " " << y << endl; int d; cin >> d; if( d == 0 ) { exit( 0 ); } return d; } signed main() { ios::sync_with_stdio( 0 ); int a = ask( 0, 0 ); int b = ask( 0, a ); ask( b / 2, a - b / 2 ); return 0; }