跳到正文

题解

题解:P16220 [ECUSTPC 2025] 浮点

PopcandyTom约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年4月10日
收录
2026年5月6日
更新
2026年11月14日
篇幅
约 2 分钟
题目
P16220

版本

  1. v2当前
  2. v1

UPD on 2026/04/12 代码实际逻辑与分析部分构造方法不一致,已重构。望审核给过。


定义 highbit⁡(x)\operatorname{highbit}(x) 为正整数 xx 二进制最高位 11 对应的数值 (别搜了,我对着 lowbit⁡\operatorname{lowbit} 硬造的)。

注意到若正整数 x,yx, y 满足 highbit⁡(x)=highbit⁡(y)\operatorname{highbit}(x) = \operatorname{highbit}(y),则 highbit⁡(x)\operatorname{highbit}(x) 在按位异或时会被异或掉,而在按位与时会保留,即:

xxor⁡y<highbit⁡(x)≤xand⁡yx \operatorname{xor} y < \operatorname{highbit}(x) \leq x \operatorname{and} y

于是我们可以得到当 n≤229n \leq 2^{29} 时的一组合法解为 229,229+1,229+2,⋯ ,229+n−12^{29}, 2^{29}+1, 2^{29}+2, \cdots, 2^{29}+n-1(显然以上数的 highbit⁡\operatorname{highbit} 均为 2292^{29})。由于输入保证 n≤106n \leq 10^6,我们可以肯定不存在无解的情况。代码实现的复杂度为 O(T+∑n)O(T + \sum n)。

AC\textcolor{#52C41A}{\texttt{AC}} 代码(请勿抄袭)
C++
#include <iostream>
using namespace std;
int t, n;
int main(){
    cin >> t;
    while(t--){
        cin >> n;
        int x = (1 << 29);
        while(n--)
            cout << x++ << ' ';
        cout << '\n';
    }
    return 0;
}
原文