Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)-B. The Bits

版权声明:本文为博主原创文章,欢迎转载。 https://blog.csdn.net/Smiler_/article/details/82108465

B. The Bits

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

题意:

给你有n个字符的01串a和b,给你重新定义了异或运算的规则,现在问你有多少种交换方法,使得交换之后两个串的异或值与原来的异或值不一样,交换的规则是在a中选择两个数字交换他们的位置。

思路:这个题要注意看题,这个异或规则和我们以前的异或规则不一样,通过分析我们可以发现我们只需要统计一个特定数字的个数即可。

#include <algorithm>
#include <vector>
#include <cstdio>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <iostream>

using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    string s1,s2;
    cin>>s1>>s2;
    long long  a=0,b=0,c=0,d=0;
    for(int i=0; i<n; i++)
    {
        if(s1[i]=='0')
        {
            if(s2[i]=='0')
            {
                a++;
            }
            else
            {
                b++;

            }
        }
        else
        {
            if(s2[i]=='0')
            {
                c++;
            }
            else
            {
                d++;
            }
        }
    }
//    cout<<a<<"  "<<b<<" "<<c<<"  "<<d<<endl;
    long long ans=0;
    ans=a*(c+d)+c*(a+b)+b*c+a*d;
    ans=ans/2;
    cout<<ans<<endl;
}

猜你喜欢

转载自blog.csdn.net/Smiler_/article/details/82108465