Description

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, 01010 OR 10011 = 11011.

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
 
题目意思:给你两个长度为n,全都是由01组成的串,这两个串按照按位或的运算方式计算会得到一个结果。
比如01010 OR 10011 = 11011。问如果交换第一个串中的某两个位能够使按位或的运算结果改变,这样的交换有多少种?

解题思路:我们会发现按位或的运算方式如果两个数中只要有1按位或的结果就是1!这样就会发现规律。
①  如果s1串的位置为0并且y串的位置也为0的话,那么只要用1和s1串这个位置的0交换,这个位置的按位或值就一定会发生变换。
② 如果s1串的位置为1,并且s2串的位置为0的话,那么如果另一个位置s1串为0,s2串为1,交换s1串的这两个位置,按位或值也会发生变换。
除了上述的情况外,交换s1串都不会使得按位或值发生变换。所以我们只要统计相应的情况的个数然后对应相乘再相加就可以了。

 #include<cstdio>
#include<cstring>
#include<algorithm>
const int MAX=1e5+;
#define ll long long int
using namespace std;
char s1[MAX],s2[MAX];
int main()
{
int n,i;
ll ans,a,b,c,d;
scanf("%d",&n);
getchar();
scanf("%s%s",s1,s2);
a=b=c=d=;
ans=;
for(i=; i<n; i++)
{
if(s1[i]==''&&s2[i]=='')
{
a++;
}
else if(s1[i]==''&&s2[i]=='')
{
b++;
}
else if(s1[i]==''&&s2[i]=='')
{
c++;
}
else if(s1[i]==''&&s2[i]=='')
{
d++;
}
}
ans=b*(a+c)+c*d;
printf("%lld\n",ans);
return ;
}

The Bits (思维+找规律)的更多相关文章

  1. Codeforces D. Little Elephant and Interval(思维找规律数位dp)

    题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...

  2. [CodeForces - 848B] Rooter's Song 思维 找规律

    大致题意: 有一个W*H的长方形,有n个人,分别站在X轴或Y轴,并沿直线向对面走,第i个人在ti的时刻出发,如果第i个人与第j个人相撞了 那么则交换两个人的运动方向,直到走到长方形边界停止,问最后每个 ...

  3. codeforces Round #440 B Maximum of Maximums of Minimums【思维/找规律】

    B. Maximum of Maximums of Minimums time limit per test 1 second memory limit per test 256 megabytes ...

  4. 1536 不一样的猜数游戏 dp思维 + 找规律

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1536 首先,要知道值为n的答案,则可以这么去想,知道值为n - 1的答案 ...

  5. 牛客国庆集训day6 B Board (模拟标记思维或找规律或分块???)

    链接:https://www.nowcoder.com/acm/contest/206/B来源:牛客网 题目描述 恬恬有一个nx n的数组.她在用这个数组玩游戏: 开始时,数组中每一个元素都是0. 恬 ...

  6. 【春训团队赛第四场】补题 | MST上倍增 | LCA | DAG上最长路 | 思维 | 素数筛 | 找规律 | 计几 | 背包 | 并查集

    春训团队赛第四场 ID A B C D E F G H I J K L M AC O O O O O O O O O 补题 ? ? O O 传送门 题目链接(CF Gym102021) 题解链接(pd ...

  7. Just Random HDU - 4790 思维题(打表找规律)分段求解

    Coach Pang and Uncle Yang both love numbers. Every morning they play a game with number together. In ...

  8. HDU1005Number Sequence(找规律)

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. 51nod_1831: 小C的游戏(Bash博弈 找规律)

    题目链接 此类博弈不需要考虑sg函数,只需要确定必胜态和必败态,解题思路一般为打败先打表找规律,而后找规律给出统一的公式.打表方式:给定初始条件(此题中为ok[0]=ok[1]=0),然后从低到高枚举 ...

随机推荐

  1. #leetcode刷题之路25- k个一组翻转链表

    给出一个链表,每 k 个节点一组进行翻转,并返回翻转后的链表.k 是一个正整数,它的值小于或等于链表的长度.如果节点总数不是 k 的整数倍,那么将最后剩余节点保持原有顺序. 示例 :给定这个链表:1- ...

  2. 用Google Cloud Plateform使用ansible创建新实例

    谷歌大法好,退aws保平安 ---假设自己现在有一个电脑(本机),先用谷歌云创一个服务器(主机) ,再通过ansible在谷歌云上创建一个服务器(节点)并进行控制 先把自己的公钥加到元数据里面,在go ...

  3. Homebrew(brew)安装MySQL成功后无法登录

    Homebrew简称brew,OSX上的软件包管理工具,在Mac终端可以通过brew安装.更新.卸载各种软件,(简直就是神器级武器). 废话不多说,没安装brew自己去百度学习安装,这里就不多说了. ...

  4. ACM1019:Least Common Multiple

    Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...

  5. Java ThreadLocal 源代码分析

    Java ThreadLocal 之前在写SSM项目的时候使用过一个叫PageHelper的插件 可以自动完成分页而不用手动写SQL limit 用起来大概是这样的 最开始的时候觉得很困惑,因为直接使 ...

  6. ubuntu18.04 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用)解决方法

    出现问题: 最近打开系统之后没声儿,抽空解决以下,谁知道安装的时候出现了这个问题,一看就是锁被占了呗 直接重启大法.....不行,看来是锁分配出问题了,找了个解锁命令 jiang@ryzen:~$ s ...

  7. 20155230 2016-2017-2 《Java程序设计》第十周学习总结

    20155230 2016-2017-2 <Java程序设计>第十周学习总结 教材学习内容总结 网络编程:就是在两个或两个以上的设备(例如计算机)之间传输数据.程序员所作的事情就是把数据发 ...

  8. 20155232 2016-2017-3 《Java程序设计》第10周学习总结

    20155232 2016-2017-3 <Java程序设计>第10周学习总结 教材学习内容总结 计算机网络 路由器和交换机组成了核心的计算机网络,计算机只是这个网络上的节点以及控制等,通 ...

  9. 2017-2018-1 20155307《信息安全技术李冬冬》实验二——Windows口令破解

    2017-2018-1 <信息安全技术>实验二--Windows口令破解 所需工具: 试验系统:Windows 2003 实验工具:LC5.SuperDic 口令破解主要有两种方法:字典破 ...

  10. 20155318 2016-2017-2 《Java程序设计》第一周学习总结

    20155318 2016-2017-2 <Java程序设计>第一周学习总结 教材学习内容总结 上周总结 上周学习了一些大学的学习方法,比如知识分为为三种:元知识.软知识和硬知识,讲述技能 ...