链接

[http://codeforces.com/contest/1066/problem/E]

题意

给你长度分别为n,m的二进制串,当b>0时,对a,b,&运算,然后b右移一位,把每次a&b的10进制结果累加对 998244353取余

分析

模拟这个过程,但有个技巧就是对b从高位开始求二进制的前缀和

具体看代码

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=998244353;
const ll N=2e5+10;
ll one[N],pw[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll i,j,k,n,m;
string a,b;
//freopen("in.txt","r",stdin);
cin>>n>>m;
cin>>a>>b;
//使位数一致在位数少的前面加0
if(n<m){
a=string(m-n,'0')+a;
}
else if(m<n){
b=string(n-m,'0')+b;
}
n=max(n,m); one[0]=(b[0]=='1');
for(i=1;i<n;i++) one[i]=one[i-1]+(b[i]=='1');//b高位开始的前缀和 pw[0]=1;
for(i=1;i<N;i++) pw[i]=pw[i-1]*2ll%mod;//计算2的幂次预处理 ll ans=0;
for(i=0;i<n;i++){
ll res=(a[i]=='1');
res=res*pw[n-i-1]%mod;//计算a这个位置的10进制值
ans=(ans+res*one[i]%mod)%mod;//之所以*one[i],是因为b右移的过程,a[i]对应的次数就是b高位开始的前缀和,注意取余mod
}
cout<<ans<<endl;
return 0;
}

E. Binary Numbers AND Sum的更多相关文章

  1. Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum

    E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个 ...

  2. Binary Numbers AND Sum CodeForces - 1066E (前缀和)

    You are given two huge binary integer numbers aa and bb of lengths nn and mmrespectively. You will r ...

  3. CF1066E Binary Numbers AND Sum

    思路: 模拟.实现: #include <iostream> using namespace std; ; ], b[]; ]; int main() { int n, m; while ...

  4. codefores 1066 E. Binary Numbers AND Sum

    这个题吧 你画一下就知道了 就拿这个例子来讲 4 5100110101 对于b串的话第5位只会经过a串的第4位,b串的第4位会经过a串的第3位和第4位.....b串的第1和第2位会经过a串的每一位 由 ...

  5. Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum (二进制,前缀和)

    题意:有两个\(01\)字符串\(a\)和\(b\),每次让\(a\)和\(b\)进行与运算,将值贡献给答案,然后将\(b\)右移一位,直到\(b=0\). 题解:因为\(a\)不变,而\(b\)每次 ...

  6. 【Leetcode_easy】1022. Sum of Root To Leaf Binary Numbers

    problem 1022. Sum of Root To Leaf Binary Numbers 参考 1. Leetcode_easy_1022. Sum of Root To Leaf Binar ...

  7. LeetCode 1022. 从根到叶的二进制数之和(Sum of Root To Leaf Binary Numbers)

    1022. 从根到叶的二进制数之和 1022. Sum of Root To Leaf Binary Numbers 题目描述 Given a binary tree, each node has v ...

  8. HDU-1390 Binary Numbers

    http://acm.hdu.edu.cn/showproblem.php?pid=1390 Binary Numbers Time Limit: 2000/1000 MS (Java/Others) ...

  9. [LeetCode#110, 112, 113]Balanced Binary Tree, Path Sum, Path Sum II

    Problem 1 [Balanced Binary Tree] Given a binary tree, determine if it is height-balanced. For this p ...

随机推荐

  1. January 18th, 2018 Week 03rd Thursday

    To strive, to seek, to find, and not to yield. 去奋斗,去寻觅,去探索,但绝不屈服. Strive for our dreams, seek the ve ...

  2. if语句的嵌套以及条件运算符和条件表达式(初学者)

    1.当if语句中的执行语句又是if语句时,则构成了if语句的嵌套情形. 其一般形式可表示为: if() { if()……; } 或: if() if()语句1: else 语句2: else if() ...

  3. MySQL视图 索引 存储过程 触发器 函数

       视图: 也就是一个虚拟表(不是真实存在的),它的本质就是根据SQL语句获取动态的数据集,并为其命名.用户使用时只需要使用命名的视图即可获取结果集,并可以当做表来使用.它的作用就是方便查询操作,减 ...

  4. 详解JavaScript中void语句的使用

    void是在JavaScript中的一个重要的关键字可被用作其单操作数之前出现一元运算符,其可以是任何类型. 此运算符指定不需要返回值,进行计算的表达式.它的语法可能是下列之一: <script ...

  5. Handler实现线程间的通信2

    与Handler实现线程间的通信1反过来MainThread中向WorkerThread中发送消息

  6. BSOJ 2414 -- 【JSOI2011】分特产

    Description JYY 带队参加了若干场ACM/ICPC 比赛,带回了许多土特产,要分给实验室的同学们. JYY 想知道,把这些特产分给N 个同学,一共有多少种不同的分法?当然,JYY 不希望 ...

  7. swift语言混编--语言交互的接口

    FFI stands for Foreign Function Interface. A foreign function interface is the popular name for the ...

  8. 原生JS添加类名 删除类名

    为 <div> 元素添加 class: document.getElementById("myDIV").classList.add("mystyle&quo ...

  9. MySQL-proxy代理导致PHP PDO::ATTR_EMULATE_PREPARES的预处理出错,MySQL报General error: 1243错误

    背景: 用的ThinkPHP5的框架.(相比之前的3.2版本,版本5都用了PDO处理数据库) 症状: 报错信息: SQLSTATE[HY000]: General error: 1243 Unknow ...

  10. 转载 Spring详细教程

    SpringMVC学习笔记---- 一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于Spring ...