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

题意:有两个\(01\)字符串\(a\)和\(b\),每次让\(a\)和\(b\)进行与运算,将值贡献给答案,然后将\(b\)右移一位,直到\(b=0\).
题解:因为\(a\)不变,而\(b\)每次右移一位,所以我们看\(b\)中\(1\)的位置在\(a\)中所对应的位置,从该位置到最低位,所有为\(1\)的位置都要算一次十进制的数贡献给答案,那么为了降低复杂度,很明显,我们使用前缀和,用十进制记录\(a\)中从低位到高位的和,然后再从低位到高位遍历\(b\),累加所有\(1\)位置在\(a\)所对应的前缀和.
代码:
int n,m;
string a,b;
ll v[N]; ll fpow(ll a,ll k){
ll res=1;
while(k){
if(k&1) res=res%mod*a%mod;
a=a*a%mod;
k>>=1;
}
return res;
} int main() {
ios::sync_with_stdio(false);cin.tie(0);
cin>>n>>m;
cin>>a>>b;
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
for(int i=0;i<n;++i){
if(a[i]=='1'){
v[i]=fpow(2,i);
}
}
for(int i=0;i<m;++i){
v[i]+=v[i-1];
}
ll ans=0;
for(int i=0;i<m;++i){
if(b[i]=='1'){
ans+=v[i];
ans%=mod;
}
} cout<<ans<<endl; return 0;
}
Codeforces Round #515 (Div. 3) 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 题意: 给出两个用二进制表示的数,然后将第二个 ...
- Codeforces Round #515 (Div. 3)
Codeforces Round #515 (Div. 3) #include<bits/stdc++.h> #include<iostream> #include<cs ...
- 构造 Codeforces Round #107 (Div. 2) B. Phone Numbers
题目传送门 /* 构造:结构体排个序,写的有些啰嗦,主要想用用流,少些了判断条件WA好几次:( */ #include <cstdio> #include <algorithm> ...
- Codeforces Round #515 (Div. 3) 解题报告(A~E)
题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...
- Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维
& -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...
- Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers
链接: https://codeforces.com/contest/1265/problem/B 题意: You are given a permutation p=[p1,p2,-,pn] of ...
- Codeforces Round #515 (Div. 3) B. Heaters【 贪心 区间合并细节 】
任意门:http://codeforces.com/contest/1066/problem/B B. Heaters time limit per test 1 second memory limi ...
- CodeForces Round #515 Div.3 D. Boxes Packing
http://codeforces.com/contest/1066/problem/D Maksim has nn objects and mm boxes, each box has size e ...
随机推荐
- 日常采坑:.NetCore上传大文件
一..NetCore上传大文件 .NetCore3.1 webapi 本地测试上传时,遇到一个坑,大点的文件直接失败,根本不走控制器方法. 二.大文件上传配置 IFormFile方式,vs IIS E ...
- 1 分钟上手,在容器中运行 Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers 这个插件允许我们在容器中运 ...
- su3和SU01中参数说明
对于SU3和SU01中的的"参数"tab栏中的参数可以自己添加和删除. 所有的参数都存在表TPARA中,并且有对应的参数的说明. 那么这些参数如何使用呢? 通常的使用是,通过类似 ...
- Django-初阶实例
调用本地css文件的方法 setting.py里面的内容 import os # Build paths inside the project like this: os.path.join(BASE ...
- Amazon Selling Partner API 开发笔记
资料整理 1.sp-api介绍:https://developer.amazonservices.com/ 2.github文档:https://github.com/amzn/selling-par ...
- selenium八大元素定位方法
1.ID定位 可以根据元素的id来定位属性,id是当前整个HTML页面中唯一的,所以可以通过id属性来唯一定位一个元素,是首选的元素定位方式.(动态ID不做考虑) # 导入webdriver和By f ...
- IGXE搬砖项目
主要的赚钱方式和倒爷其实是差不多的,自动检测igxe平台上价格与buff相差8.5%以上的饰品,按照历史价格进行一定的过滤,防止翻车,然后自动购买. 2019年经历了十几次的改进以对抗同行的脚本,到1 ...
- 2.kafka架构深入——生产者
一个topic有多个partition,每个partition又有多个副本,在这些副本中又有一个leader和多个follower. 1)分区的原因 (1)方便在集群中扩展,每个Partition可以 ...
- python atexit模块学习
python atexit模块 只定义了一个register模块用于注册程序退出时的回调函数,我们可以在这个函数中做一下资源清理的操作 注:如果程序是非正常crash,或者通过os._exit()退出 ...
- 二:SpringBoot-配置Log4j2,实现不同环境日志打印
SpringBoot-配置Log4j2,实现不同环境日志打印 日志打印之外观模式 1.日志配置 2.Log4j2的配置文件 3.简单的测试程序 日志打印之外观模式 每一种日志框架都有自己单独的API, ...