E. Binary Numbers AND Sum

题目链接:https://codeforces.com/contest/1066/problem/E

题意:

给出两个用二进制表示的数,然后将第二个二进制不断地往右边移一位,每次答案加上这两个的交集,求最后的答案。

题解:

考虑第二个二进制每一位对答案的贡献就行了,然后对第一个二进制算前缀和就ok了。

代码如下:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+,MOD = ;
ll n,m;
char s1[N],s2[N];
ll sum[N];
ll qp(ll a,ll b){
ll ans = ;
while(b){
if(b&) ans=a*ans%MOD;
a=a*a%MOD;
b>>=;
}
return ans ;
}
int main(){
scanf("%d%d",&n,&m);
scanf("%s",s1);
scanf("%s",s2);
if(s1[n-]=='') sum[]=;
for(int i=n-;i>=;i--){
if(s1[i]=='') sum[n-i-]=(sum[n-i-]+qp(,n--i))%MOD;
else sum[n-i-]=sum[n-i-];
}
ll ans = ;
for(int i=m-;i>=;i--){
if(s2[i]==''){
ans=(ans+sum[min(m--i,n-)])%MOD;
}
}
cout<<ans;
return ;
}

Codeforces Round #515 (Div. 3) E. Binary Numbers AND Sum的更多相关文章

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

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

  2. Codeforces Round #515 (Div. 3)

    Codeforces Round #515 (Div. 3) #include<bits/stdc++.h> #include<iostream> #include<cs ...

  3. 构造 Codeforces Round #107 (Div. 2) B. Phone Numbers

    题目传送门 /* 构造:结构体排个序,写的有些啰嗦,主要想用用流,少些了判断条件WA好几次:( */ #include <cstdio> #include <algorithm> ...

  4. Codeforces Round #515 (Div. 3) 解题报告(A~E)

    题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...

  5. 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 ...

  6. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  7. 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 ...

  8. Codeforces Round #515 (Div. 3) B. Heaters【 贪心 区间合并细节 】

    任意门:http://codeforces.com/contest/1066/problem/B B. Heaters time limit per test 1 second memory limi ...

  9. 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 ...

随机推荐

  1. Kubernetes-tutorials(五)

    The tutorials use Katacoda to run a virtual terminal in your web browser that runs Minikube, a small ...

  2. 3155: Preprefix sum

    3155: Preprefix sum https://www.lydsy.com/JudgeOnline/problem.php?id=3155 分析: 区间修改,区间查询,线段树就好了. 然后,这 ...

  3. LeetCode:5. Longest Palindromic Substring(Medium)

    原题链接:https://leetcode.com/problems/longest-palindromic-substring/description/ 1. 题目要求:找出字符串中的最大回文子串 ...

  4. mac 安装php redis扩展

    git clone git://github.com/nicolasff/phpredis.git cd ./phpredis phpize 如果报 Cannot find autoconf. Ple ...

  5. howto:在构建基于debian的docker基础镜像时,更换国内包源

    debian经常被用作构建应用镜像的基础镜像,如微软在构建linux下的dotnetcore基础镜像时,提供了基于debian 8(jessie)和debian 9(stretch)的镜像. 由于这些 ...

  6. Spring MVC 开发 配置

    1.首先在web.xml中配置一个DispatcherServlet,并通过<servlet-mapping>指定需要拦截的url. 下面xml中配置一个拦截.html为后缀的url. & ...

  7. Linux-Shell脚本编程-学习-5-Shell编程-使用结构化命令-if-then-else-elif

    if-then语句 if-then语句格式如下 if comman then command fi bash shell中的if语句可鞥会和我们接触的其他if语句的工作方式不同,bash shell的 ...

  8. [POJ3585]Accumulation Degree

    题面 \(\text{Solution:}\) 有些题目不仅让我们做树型 \(\text{dp}\) ,而且还让我们换每个根分别做一次, 然后这样就愉快的 \(\text{TLE}\) 了,所以我们要 ...

  9. 剑指offer-调整数组顺序使奇数位于偶数前面13

    题目描述 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变. class Solu ...

  10. NLP系列-中文分词(基于词典)

    中文分词概述 词是最小的能够独立活动的有意义的语言成分,一般分词是自然语言处理的第一项核心技术.英文中每个句子都将词用空格或标点符号分隔开来,而在中文中很难对词的边界进行界定,难以将词划分出来.在汉语 ...