Codeforces Round #781 D. GCD Guess
题目大意
交互题,每次询问给出 , 得到 , 次询问内求出 。
思路
考虑通过回答来确定 二进制上每一位的值,我们每次可以记录 到 位的答案为 ,查询 来确定第 位的值,如果得到的回答 ,那么第 位就为 ,否则为 。
代码
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using TP = tuple<int, int, int>;
#define all(x) x.begin(),x.end()
//#define int LL
//#define lc p*2
//#define rc p*2+1
//#define endl '\n'
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
//#pragma warning(disable : 4996)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
const double eps = 1e-8;
const LL MOD = 1000000007;
const LL mod = 998244353;
const int maxn = 200010;
LL T, A[35];
void solve()
{
LL res, ans = 0;
for (int i = 0; i < 30; i++)
{
LL a = A[i] - ans, b = A[i] + A[i + 1] - ans;
cout << "? " << a << ' ' << b << endl;
cin >> res;
if (res == A[i + 1])
ans ^= (1LL << i);
}
cout << "! " << ans << endl;
}
int main()
{
IOS;
LL num = 1;
for (int i = 0; i <= 30; i++)
A[i] = num, num *= 2;
cin >> T;
while (T--)
solve();
return 0;
}
本文作者:Prgl
本文链接:https://www.cnblogs.com/Prgl/p/16122445.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
分类:
,
标签:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步