XOR Break — Solo Version

题意

思路

最多两步解决

1. 一步:

只要满足 ((n^m) < n) 即可一步,只要在第一个mi = 1的地方n也有1 无论如何都可以随便改n得到m

2. 无解的情况:

只要在第一个mi=1的时候n(i) -> n(最高位-1) 没有1 出现肯定无法解决

3. 二步:

类似于 10110 -> 00001

10110 ->

10101 ->

00001

只需要得到第一个mi = 1位置的1就行了

我们需要找到mi第一次出现1的位置i

再找到ni在mi第一次出现1的位置前 最后一次出现1的位置

中间态答案就是 (n ^ (2^(idx))) + 2^(i)

相当于牺牲了一个最后一个idx 而n前面的不变得到了 和mi相同的1

code

#include<iostream>
#include<cstdio>
#include<stack>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<vector>
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define  long long
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int INF = 1e18 + 10;
const int N = 1e5 + 10;
const int M = 1e7 + 10;
const int mod = 1e9 + 7;
int n, m, k, x, now, ans;
int qcal(int a, int b) { int res = 1; while (b) { if (b & 1) res = res * a % mod; b >>= 1; a = a * a % mod; } return res; }
int a[N], b[N];
bool is_prime(int n) { if (n < 2) return false; for (int i = 2; i <= n / i; i++) { if (n % i == 0) { return false; } }return true; }


void gzy()
{
    cin >> n >> m;
    if((n ^ m) < n)
    {
        cout << 1 << endl;
        cout << n << ' ' << m << endl;
        return;
    }
    int cnt = 0;
    int idx = -1; // 最后一次出现1的位置
    for(int i = 62;~i;i --)
    {
        if((n >> i) & 1)
        {
            cnt ++;
            idx = i;
        }
        if((m >> i) & 1)
        {
            if(cnt < 2) 
            {
                cout << -1 << endl;
                return;
            }
            else
            {
                // cout << idx << endl;
                // cout << i << endl;
                cout << 2 << endl;
                cout << n << ' ';
                cout << (n ^ (1LL << idx) + (1LL << i)) << ' ';
                cout << m << endl;
                return;
            }
        }
    }
}

signed main()
{
    int _ = 1; cin >> _;
    while (_ --) gzy();
    return 0;
}
// /**
//  *  ┏┓   ┏┓+ +
//  * ┏┛┻━━━┛┻┓ + +
//  * ┃       ┃
//  * ┃   ━   ┃ ++ + + +
//  *  ████━████+
//  *  ◥██◤ ◥██◤ +
//  * ┃   ┻   ┃
//  * ┃       ┃ + +
//  * ┗━┓   ┏━┛
//  *   ┃   ┃ + + + +Code is far away from  
//  *   ┃   ┃ + bug with the animal protecting
//  *   ┃    ┗━━━┓ 神兽保佑,代码无bug 
//  *   ┃  	    ┣┓
//  *    ┃        ┏┛
//  *     ┗┓┓┏━┳┓┏┛ + + + +
//  *    ┃┫┫ ┃┫┫
//  *    ┗┻┛ ┗┻┛+ + + +
//  */

  • 26
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值