1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <bits/stdc++.h> using namespace std;
const int N = 2e5 + 10; const int inf = 1 << 30; const long long llinf = 1ll << 60; const double PI = acos(-1);
#define lowbit(x) (x&-x) typedef long long ll; typedef double db; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<db, db> pdd; typedef pair<ll, int> pli;
#define int long long int n, m, k, q; void work() { cin >> n >> m; auto query = [&](int x, int y) { cout << "? " << x << ' ' << y << endl; }; auto answer = [&](int x, int y) { cout << "! " << x << ' ' << y << endl; }; int dis1, dis2, dis3, dis4; query(1, 1); cin >> dis1; query(n, 1); cin >> dis2; query(1, m); cin >> dis3; auto cross = [&](int k1, int b1, int k2, int b2) { int x = (b2 - b1) / (k1 - k2); int y = k1 * x + b1; return make_pair(x, y); }; auto p1 = cross(-1, dis1 + 2, 1, dis2 - n + 1); auto p2 = cross(-1, dis1 + 2, 1, m - dis3 - 1); if (1 <= p1.first && p1.first <= n && 1 <= p1.second && p1.second <= m) { query(p1.first, p1.second); cin >> dis4; if (dis4 == 0) answer(p1.first, p1.second); else answer(p2.first, p2.second); } else answer(p2.first, p2.second); } main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t --> 0) { work(); } }
|