跳到正文

个人记录

P11485 「Cfz Round 5」Non-breath Oblige

chengcheng_2015约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟

版本

  1. v1当前

P11485 「Cfz Round 5」Non-breath Oblige

解题思路

C++
如果s等于t 不要变

s | x == 2^n-1
s在二级制中如果某一位是0
x的那一位必须为1

s在二级制中如果某一位是1
因为代价之和要最小
所以x的那一位也为1

所以第一次x为 2^n-1
s为 2^n-1

因为 2^n-1 跟小于 2^n 按位或等于 2^n-1
第2次一定能变为y

代码

C++
#include<bits/stdc++.h>
using namespace std;
int main(){
    int T;
    cin >> T;
    while(T--){
        int n, s, t;
        cin >> n >> s >> t;
        if(s==t)cout << "0\n";
        else{
            int c=0;
            c += (s^(1<<n)-1);
            c += (t^(1<<n)-1);
            cout << c << '\n';
        }
    }
    return 0;
}
原文