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. NOIP Day1总结

    Day1T1玄学考试 在开始之前,我犯了考前综合症,各种不安各种焦躁. 结果当我去到考场的时候,看了T1...... T1:road 这不是裸的原题么这!我当时心里瞬间想到积木大赛.这明显就是积木大赛 ...

  2. ABAP术语-URL

    URL 原文:http://www.cnblogs.com/qiangsheng/archive/2008/03/20/1114193.html Uniform Resource Locator (U ...

  3. 在软件webstorm中给img标签加入class报错显示错误selector matches unknow element

    如题,怎么也搞不懂,在其他软件没出过这种问题,偏偏在webstorm中,显示class选择器未匹配到元素:哪位大神知道怎么解决这个问题.

  4. e.currentTarget与e.target

    e.currentTarget指的是注册了事件监听器的对象,而e.target指的是该对象里的子对象   html中 <div id="addBtn" v-on:click= ...

  5. easyui图标

    只要在icons属性上,加上图标对应的名字,easyUI就会显示对应的图标,这些图标都是easyui内置的.

  6. js 里常用的数组操作方法

    var ar=[112,44,55,66,77,88,99,'00',77]; var ar1=['ddd','fff','ggg']; //concat() 拼接一个或多个数组: //console ...

  7. Security 安全框架1

    security 过滤器链 检查请求是否有请求信息-主要校验规则 UsernamePasswordAuthenticationFilter: 处理表单登录, 请求是否带用户名密码 BasicAuthe ...

  8. 用Python批量下载DACC的MODIS数据

    本人初次尝试用Python批量下载DACC的MODIS数据,记下步骤,提醒自己,数据还在下载,成功是否未知,等待结果中...... 若有大佬发现步骤有不对之处,望指出,不胜感激. 1.下载Python ...

  9. DMZ靶场渗透

    0x00 目标站点www.test.ichunqiu 0x01 尝试登陆系统 -尝试弱密码登陆 结果:forbidden!!! -尝试万能账号密码登陆 1‘ or 1=1--+ 和 1‘ or 1=1 ...

  10. BurpSuite—-Target模块(目标模块)

    Target功能 目标工具包含了SiteMap,用你的目标应用程序的详细信息.它可以让你定义哪些对象在范围上为你目前的工作,也可以让你手动测试漏洞的过程,Target分为site map和scope两 ...