首页 > 其他分享 >XOR Break — Solo Version

XOR Break — Solo Version

时间:2024-03-16 20:59:35浏览次数:19  
标签:Solo const int res mi long Break Version include

题意

思路

最多两步解决

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 
//  *   ┃  	    ┣┓
//  *    ┃        ┏┛
//  *     ┗┓┓┏━┳┓┏┛ + + + +
//  *    ┃┫┫ ┃┫┫
//  *    ┗┻┛ ┗┻┛+ + + +
//  */

标签:Solo,const,int,res,mi,long,Break,Version,include
From: https://blog.csdn.net/chunyou_/article/details/136651197

相关文章

  • break、continue与goto关键字
    breakbreak在任何循环语句的主体部分,均可用break控制循环的流程。break用于强行退出循环,不执行循环中剩余的语句。(break语句也在switch语句中使用)代码举例publicclassBreakDemo{publicstaticvoidmain(String[]args){inti=0;while(i<1......
  • 猫头虎分享已解决Bug || 服务版本冲突(Service Version Conflict):VersionMismatchError,
    博主猫头虎的技术世界......
  • Doremy's Drying Plan (Hard Version)
    我们先来看看简单版本的想法,非常具有启发性大致的思路见这篇文章下面是对这篇文章具体操作的阐释我们先将所有区间按照左端点单调递增排序,并统计每一个区间中\(c_i=1\)的个数(这个直接用前缀和就好了,设\(sum[i][j]\)表示前\(i\)个数中\(c_k=j\)的个数),枚举其中一个区间(设为\([l,r......
  • 【WEEK2】 【DAY5】Data Processing and Redirection - Data Processing【English Ver
    2024.3.8FridayFollowingthepreviousarticle【WEEK2】【DAY4】DataProcessingandRedirection-MethodsofResultRedirection【EnglishVersion】Contents5.2.DataProcessing5.2.1.SubmittingProcessedData5.2.1.1.Thesubmittedfieldnamematches......
  • 数据库练习发生的error—— check the manual that corresponds to your MySQL server
    记录一下发生的错误。 checkthemanualthatcorrespondstoyourMySQLserverversionfortherightsyntaxtousenear''id'),参考链接:完美解决ERROR1064(42000):YouhaveanerrorinyourSQLsyntax...near…_responsecode:420001064r......
  • 解决 K8sApi 部署后报 Unknown apiVersionKind apps/v1/Deployment is it registered?
    该功能在本地调试时是正常的,部署到服务器时报错。Jdk11+SpringBoot2.7.5,依赖:<dependency><groupId>io.kubernetes</groupId><artifactId>client-java</artifactId><version>20.0.0</version>......
  • node: /lib64/libm.so.6: version `GLIBC_2.27‘ not found问题解决方案
    场景centos7服务器使用nvm安装的node之后,只要使用npm或者node,均会出现以下问题。npm-vnode:/lib64/libm.so.6:version`GLIBC_2.27'notfound(requiredbynode)node:/lib64/libc.so.6:version`GLIBC_2.25'notfound(requiredbynode)node:/lib64/libc.so.6:ver......
  • mavlink version
    mavlink版本号获取方式mavlink本身提供了一种版本号校验的方式,开源的代码生成器对此做了处理的,在xml把字段类型定义成uint8_t_mavlink_version,生成的时候应该就是直接取xml的version,交互双方可以直接根据此字段校验双方版本。示例在官方提供的common.xml文件中,对HEARTBEAT消息......
  • CF1264D2 Beautiful Bracket Sequence (hard version) 题解
    括号深度的本质,其实就是删除若干个字符以后使得左边一半全是(,右边一半全是),最终(的个数的最大值。那么就一定存在一个位置使得在这个位置以及之前的字符中(的个数等于这个字符后)的个数。考虑枚举这个位置,记它左边的(的个数为\(a\)、?的个数为\(x\),右边的)的个数......
  • CF1824B1 LuoTianyi and the Floating Islands (Easy Version) 题解
    分析按照\(k\)的奇偶分开考虑。\(k\)为奇数。一个好的节点有且仅有一个在任意两个有人的节点\(i,j\)的路径的交点上的最优位置。若该交点偏移\(1\)步,则必然会使路径长度和\(+1\)。故期望为\(1\)。\(k\)为偶数。任意一个好的节点仍然在任意两个有人的节点\(i,j\)的......