题解:P11485 「Cfz Round 5」Non-breath Oblige

· · 题解

P11485 「Cfz Round 5」Non-breath Oblige 题解

题目传送门

题意

题目描述清晰,不多讲述。

结论

$\forall s,t \in [0,2^n)$ 且 $s \ne t$,都有 $ans=(s\oplus(2^n-1))+(t\oplus(2^n-1))$,其中 $ans$ 为最终的代价。 ### 证明 若 $s = t$,那么答案为 $0$。 若 $s\ne t$,如果我们要使 $s\oplus x$ 以及 $t \oplus x$ 的代价最小,那么我们将 $s$ 变成 $2^n-1$,再将 $2^n-1$ 变成 $t$ 所需要的代价一定严格不大于其它 $x$ 所花费的代价。 ::::info[code]{open} ```cpp #include<bits/stdc++.h> using namespace std; signed main(){ int T,n,s,t; for(cin>>T;T--;){ cin>>n>>s>>t; if(s==t)puts("0"); else cout<<((1<<n)-1^s)+((1<<n)-1^t)<<'\n'; } } ``` ::::