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. node里使用supervisor

    1.npm -g install supervisor(安装) 2.用cd命令定位到项目的根目录 3.supervisor bin/www

  2. Ubuntu16.04 解决matplotlib乱码或者中文显示不了的问题(可用)

    一. 下载字体 SimHei.ttf 复制到linux字体库中 sudo cp ~/SimHei.ttf /usr/share/fonts/SimHei.ttf 二.查看matplotlib配置 In ...

  3. 菜鸟级渣渣 关于MAC系统开发java的吐槽

    最开始买电脑的时候不知道为什么脑子一抽买了个苹果.因为不知道和谁聊的.后期服务器大部分都是linux系统,后期也要学linux系统.mac系统类似linux系统.然后就买了个mac,感觉凭借自己的聪明 ...

  4. JavaScript的迭代函数与迭代函数的实现

    前言 ​ 如果对技术很自信,请直接看 实现的源码 ​ 如果想回顾一下基础,请按文章顺序阅读 说到迭代方法,最先想到的是什么?forEach还是map,迭代的方法ES5提供了5种方法 以下定义来自 Ja ...

  5. Hive配置项的含义详解

    关于MetaStore:metastore是个独立的关系数据库,用来持久化schema和系统元数据. hive.metastore.local:控制hive是否连接一个远程metastore服务器还是 ...

  6. NodeJS设置Header解决跨域问题

    转载: NodeJS设置Header解决跨域问题 app.all('*', function (req, res, next) { res.header('Access-Control-Allow-O ...

  7. Hadoop学习总结之Map-Reduce的过程解析

    一.客户端 Map-Reduce的过程首先是由客户端提交一个任务开始的. 提交任务主要是通过JobClient.runJob(JobConf)静态函数实现的: public static Runnin ...

  8. wmware 10 升级到11后,macos不能运行的问题

    解决方案: 1.由于wmware升级,原来的unlocker已不能使用. 所以得升级unlocker版本,目前支持wmware11的最新版本是2.0.4 http://www.insanelymac. ...

  9. MySQL入门篇(六)之mysqldump备份和恢复

    一.备份单个数据库 1.备份命令:mysqldump MySQL数据库自带的一个很好用的备份命令.是逻辑备份,导出 的是SQL语句.也就是把数据从MySQL库中以逻辑的SQL语句的形式直接输出或生成备 ...

  10. OpenStack入门篇(三)之KVM介绍及安装

    1.什么是虚拟化? 虚拟化是云计算的基础.简单的说,虚拟化使得在一台物理的服务器上可以跑多台虚拟机,虚拟机共享物理机的 CPU.内存.IO 硬件资源,但逻辑上虚拟机之间是相互隔离的. 物理机我们一般称 ...