跳到正文

题解

P11485题解

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

文章信息

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

版本

  1. v1当前

思路 1.判断S是否等于T,如果相等,那么代价为0 2.将S变成2的n次方-1,判断此时是否等于T,如果相等,那么代价为(S^(2^n-1)) 3.将S’变成T,那么此时的代价为(S’^T)+(S^(2^n-1))


代码

C++
#include<bits/stdc++.h>
using namespace std;
int main(){
	int T;
	cin>>T;
	for(int i=1;i<=T;i++){
		long long n,s,t;
		cin>>n>>s>>t;
		long long pw=pow(2,n);
		long long dj=0;
		if(s==t){
			cout<<0<<endl;
		}else{
			dj+=s^(pw-1);
			s=pw-1;
			if(s==t){
				cout<<dj<<endl;
			}else{
				dj+=s^t;
				s=t;
				cout<<dj<<endl;
			}
		}
	}
	return 0;
}
原文