The Bits(找规律)

第七次个人赛

Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question:

Given two binary numbers aa and bb of length nn. How many different ways of swapping two digits in aa (only in aa, not bb) so that bitwise OR of these two numbers will be changed? In other words, let cc be the bitwise OR of aa and bb, you need to find the number of ways of swapping two bits in aa so that bitwise OR will not be equal to cc.

Note that binary numbers can contain leading zeros so that length of each number is exactly nn.

Bitwise OR is a binary operation. A result is a binary number which contains a one in each digit if there is a one in at least one of the two numbers. For example, 010102010102 OR 100112100112 = 110112110112.

Well, to your surprise, you are not Rudolf, and you don't need to help him…… You are the security staff! Please find the number of ways of swapping two bits in aa so that bitwise OR will be changed.

Input

The first line contains one integer nn (2≤n≤1052≤n≤105) — the number of bits in each number.

The second line contains a binary number aa of length nn.

The third line contains a binary number bb of length nn.

Output

Print the number of ways to swap two bits in aa so that bitwise OR will be changed.

Sample Input

Input

5
01011
11001

Output

4

Input

6
011000
010011

Output

6

Hint

In the first sample, you can swap bits that have indexes (1,4)(1,4), (2,3)(2,3), (3,4)(3,4), and (3,5)(3,5).情况

In the second example, you can swap bits that have indexes (1,2)(1,2), (1,3)(1,3), (2,4)(2,4), (3,4)(3,4), (3,5)(3,5), and (3,6)(3,6).

OR :

是  或 ( | ) 的意思,如果两位中有一个是 1 ,那么或 完之后的结果就是 1

XOR:

是  异或 (^)  的意思,如果两位相同,结果为 0,不同 为 1

题意:两个二进制数字a,b,然后进行or运算,然后进行交换数字a,如果数字交换以后,得到的结果不相同,求数字交换以后的位置。

思路:我们可以知道与运算有四种情况分别为:

           a=0,a=0,a=1,a=1

           b=0,b=1,b=0,b=1

两种情况:

         ① 对于b二进制如果是1,a 的值对or运算以后的结果没有影响,所以我们找b=0和a =0的数量,然后在找到b=0,a=1和b=1,a=1的数量,这时候有两个情况:

                a=0,b=0对应着a=1,b=0和a=1,b=1,计算出来:sum=sum(0,0)*sum(1,0)+sum(0,0)*sum(1,1);

         ② 还有一种情况是a=1,b=0对应着a=0,b=1计算出来:sum=sum(1,0)*sum(0,1);

        相加得出结果   (#^.^#)

 

 

#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>

typedef long long LL;
const long long INF = 0x3f3f3f3f;
const long long mod = 1e9+7;
const double PI = acos(-1.0);
const int dir4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir8[8][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}};
const int maxx = 100010;
using namespace std;
int main()
{
    LL n;
    LL ans=0;
    char s[maxx];
    char c[maxx];
    scanf("%lld",&n);
    cin>>s;
    cin>>c;
    LL x=0,y=0,a=0,b=0;
    for(LL i=0;i<n;i++)
    {
        if(s[i]=='0'&&c[i]=='0')
            a++;
        if(s[i]=='1'&&c[i]=='0')
            b++;
        if(s[i]=='1'&&c[i]=='1')
            x++;
        if(s[i]=='0'&&c[i]=='1')
            y++;
    }
    ans=a*b+a*x+b*y;
    printf("%lld\n",ans);
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值