E. Binary Numbers AND Sum
链接
[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的更多相关文章
- Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum
E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个 ...
- 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 ...
- CF1066E Binary Numbers AND Sum
思路: 模拟.实现: #include <iostream> using namespace std; ; ], b[]; ]; int main() { int n, m; while ...
- codefores 1066 E. Binary Numbers AND Sum
这个题吧 你画一下就知道了 就拿这个例子来讲 4 5100110101 对于b串的话第5位只会经过a串的第4位,b串的第4位会经过a串的第3位和第4位.....b串的第1和第2位会经过a串的每一位 由 ...
- Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum (二进制,前缀和)
题意:有两个\(01\)字符串\(a\)和\(b\),每次让\(a\)和\(b\)进行与运算,将值贡献给答案,然后将\(b\)右移一位,直到\(b=0\). 题解:因为\(a\)不变,而\(b\)每次 ...
- 【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 ...
- 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 ...
- HDU-1390 Binary Numbers
http://acm.hdu.edu.cn/showproblem.php?pid=1390 Binary Numbers Time Limit: 2000/1000 MS (Java/Others) ...
- [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 ...
随机推荐
- https://www.testingcircus.com/tell-me-about-yourself-6-sample-answers-software-testers/
https://www.testingcircus.com/tell-me-about-yourself-6-sample-answers-software-testers/ Tell Me Abou ...
- windows任务管理器怎么知道多个IIS网站进程分别对应哪个网站
摘要: 1.IIS网站对应的进程名一般叫w3wp.exe (windows2008系统为例,其他类似) 2.windows默认的任务管理器只能看到多个同名的进程名w3wp.exe,没法区别分别对应哪个 ...
- logstash过滤器插件filter详解及实例
1.logstash过滤器插件filter 1.1.grok正则捕获 grok是一个十分强大的logstash filter插件,他可以通过正则解析任意文本,将非结构化日志数据弄成结构化和方便查询的结 ...
- leetcode 5. Longest Palindromic Substring [java]
public String longestPalindrome(String s) { String rs = ""; int res = 0; for(int i = 0; i& ...
- DStream算子讲解(一)
先把目录列好,方便有条理的进行整理
- ethereum/EIPs-1078 Universal login / signup using ENS subdomains
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1078.md eip title author discussions-to status ...
- k8s调度的亲和性和反亲和性
文章转自 http://ju.outofmemory.cn/entry/278349 https://www.jianshu.com/p/102c4df69af9 RequiredDuringSche ...
- 前台返回json数据的常用方式+常用的AJAX请求后台数据方式
我个人开发常用的如下所示: 之所以像下面这样下,一是前台Ajax,二是为安卓提供接口数据 现在常用的是返回JSON数据,XML的时代一去不复返 JSON相对于XML要轻量级的多 对JSON不是十分熟悉 ...
- MATLAB——径向基网络拟合曲线和分类
1.:.:; rand('state',pi); %指定状态,产生相同的随机数 T=sin(*P)+rand(,length(P)); % 给正弦函数加噪声 plot(P,T,'o') % net=n ...
- PAT A1117 Eddington Number (25 分)——数学题
British astronomer Eddington liked to ride a bike. It is said that in order to show off his skill, h ...