CF1365G Secure Password 题解
Description
本题是交互题。
有一个固定的数组
你需要在最多
Solution
首先有一个
考虑怎么优化到
容易发现要想优化掉那个
所以只要给每个
经过计算,这些
总询问次数:
Code
#include <bits/stdc++.h> #define int int64_t const int kMaxN = 1e3 + 5; int n; int id[kMaxN], val[13]; int ask(std::vector<int> vec) { if (!vec.size()) return 0; std::cout << "? " << vec.size() << ' '; for (auto x : vec) std::cout << x << ' '; std::cout << std::endl; int x; std::cin >> x; return x; } void dickdreamer() { std::cin >> n; int cnt = 0; for (int i = 0; i < (1 << 13); ++i) { if (__builtin_popcount(i) == 6) { id[++cnt] = i; if (cnt == n) break; } } for (int i = 0; i < 13; ++i) { std::vector<int> vec; for (int j = 1; j <= n; ++j) if (~id[j] >> i & 1) vec.emplace_back(j); val[i] = ask(vec); } std::cout << "! "; for (int i = 1; i <= n; ++i) { int res = 0; for (int j = 0; j < 13; ++j) if (id[i] >> j & 1) res |= val[j]; std::cout << res << ' '; } } int32_t main() { #ifdef ORZXKR freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0); int T = 1; // std::cin >> T; while (T--) dickdreamer(); // std::cerr << 1.0 * clock() / CLOCKS_PER_SEC << "s\n"; return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步