1 条题解

  • 0
    @ 2025-8-24 22:39:20

    自动搬运

    查看原文

    来自洛谷,原作者为

    avatar chen_zhe
    Aya 敲可爱的~

    搬运于2025-08-24 22:39:20,当前版本为作者最后更新于2022-08-07 17:17:28,作者可能在搬运后再次修改,您可在原文处查看最新版

    自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多

    以下是正文


    文文的构造游戏

    解法

    观察到当 m=1m=1 则必定无解。

    m=2m=2 时,对于偶数 ss,可以将其拆成两个 s2\dfrac{s}{2},这样异或和为 00 且加起来为 ss。即,当 ss 为偶数且 m2m \geq 2 都存在一种构造方式。

    ss 为奇数时是必定无解的。将 ss 拆成若干个正整数相加,会发现 a1,a2,,ana_1,a_2,\dots,a_n 的二进制最末位必定出现奇数次 11,这就使得 11 无法完全抵消,最后的 $a_1 \operatorname{xor} a_2\operatorname{xor} \dots a_n$ 的最小值也是 11

    #include <iostream>
    #include <cstdio>
    using namespace std;
    int main()
    {
        int T;
        cin >> T;
        while (T--)
        {
            long long s,m;
            cin >> s >> m;
            if (m==1 || (s&1))
                puts("-1");
            else
                cout << 2 << " " << s/2 << " " << s/2 << endl;
        }
        return 0;
    }
    
    • 1

    信息

    ID
    7829
    时间
    2000ms
    内存
    512MiB
    难度
    2
    标签
    递交数
    0
    已通过
    0
    上传者