周六第七次课
B3919 [语言月赛 202401] 二进制与一
给我们一个数字
要知道
#include<bits/stdc++.h>
using namespace std;
long long n, q;
long long sum;
int main(){
cin >> n>> q;
while(q--){
long long k;
cin >> k;
long long x = 0;
if((n >> k - 1) & 1){
sum += 0;
}else{
for(int i = 1;i <= k - 1;i++){
if((n >> i - 1) & 1){
continue;
}
x += 1LL << (i - 1);
}
sum += (x + 1);
n += (x + 1);
}
}
cout << sum;
return 0;
}
P11485 「Cfz Round 5」Non-breath Oblige
给出3个正整数
- 必须满足
x<2^n ; - 必须满足
s\lor x=2^n-1 ,其中\lor 为按位或运算; - 你需要花费
s\oplus x 的代价,其中\oplus 为按位异或运算。
如果
#include<bits/stdc++.h>
using namespace std;
int x;
int main(){
cin >> x;
while(x--){
int n, s, t;
cin >> n>> s>> t;
if(s == t){
cout << 0<< endl;
continue;
}
int a = (1 << n) - 1;
cout << (s ^ a) + (a ^ t)<< endl;
}
return 0;
}