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 ...
随机推荐
- ORA-32004解决办法
ORA-32004 解释是: 产生问题的原因是一个过时的参数,这个参数是早在8i,9i中使用的,在11g中已经废掉了 这个参数就是pfile中的*.sql_trace 用spfile 生成一个pfil ...
- kubernets之计算资源
一 为pod分配cpu,内存以及其他的资源 1.1 创建一个pod,同时为这个pod分配内存以及cpu的资源请求量 apiVersion: v1 kind: Pod metadata: name: ...
- SDUST数据结构 - chap4 串
函数题: 6-1 查找子串: 裁判测试程序样例: #include <stdio.h> #define MAXS 30 char *search(char *s, char *t); vo ...
- 命令模式与go-redis command设计
目录 一.什么是命令(Command)模式 二.go-redis command相关代码 三.总结 一.什么是命令(Command)模式 命令模式是行为型设计模式的一种,其目的是将一个请求封装为一个对 ...
- PAT Advanced 1004 Counting Leaves
题目与翻译 1004 Counting Leaves 数树叶 (30分) A family hierarchy is usually presented by a pedigree tree. You ...
- ROS教程(二):创建工作空间(图文)
ros教程:创建工作空间 目录 前言 一.工作空间? 二.创建一个工作空间 1.创建目录 2.编译 前言 使用catkin创建一个工作空间 一.工作空间? 在ROS系统下,我们所有的项目都放在一个工作 ...
- 转 Fiddler4 手机抓包
Fiddler4 手机抓包 文章转自:https://www.cnblogs.com/zhengna/p/10876954.html 1.要对计算机Fiddler进行配置,允许远程计算机连接. 2. ...
- 在OpenDaylight controller上开发App
安装环境:Ubuntu18.04 一.安装依赖 1. 安装JDK: sudo apt update sudo apt install openjdk-8-jdk-headless 选择默认的 JDK: ...
- 向HDFS中上传任意文本文件,如果指定的文件在HDFS中已经存在,由用户指定是追加到原有文件末尾还是覆盖原有的文件
1 import java.io.FileInputStream; 2 import java.io.IOException; 3 import java.util.Scanner; 4 5 impo ...
- Most basic operations in Go are not synchronized. In other words, they are not concurrency-safe.
Most basic operations in Go are not synchronized. In other words, they are not concurrency-safe. htt ...