1017 B. The Bits

时间:2023-03-09 22:08:55
1017 B. The Bits

链接

[http://codeforces.com/contest/1017/problem/B]

题意

给你两个长度为n,包含0和1的字符串a和b,有一种操作swap a中的任意两个字符使得a&b的值改变

思路

首先任意位置对位情况有图片中这4种,这题关键是如何去重,我们知道b串的是0才有可能交换a中字符使a&b的值改变

1017 B. The Bits

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b,c,d;
int n,i;
string o,k;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("in.txt","r",stdin);
while(cin>>n)
{
cin>>o>>k;
b=a=c=d=0;
//ll ans=0;
for(i=0;i<n;i++){
if(o[i]=='0'&&k[i]=='0') a++;
if(o[i]=='0'&&k[i]=='1') b++;
if(o[i]=='1'&&k[i]=='0') c++;
if(o[i]=='1'&&k[i]=='1') d++;
}
cout<<a*c+a*d+c*b<<endl;
}
return 0;
}