题目链接


Vus the Cossack has two binary strings, that is, strings that consist only of “0” and “1”. We call these strings a and b. It is known that |b|≤|a|, that is, the length of b is at most the length of a.

The Cossack considers every substring of length |b| in string a. Let’s call this substring c. He matches the corresponding characters in b and c, after which he counts the number of positions where the two strings are different. We call this function f(b,c).

For example, let b=00110, and c=11000. In these strings, the first, second, third and fourth positions are different.

Vus the Cossack counts the number of such substrings c such that f(b,c) is even.

For example, let a=01100010 and b=00110. a has four substrings of the length |b|: 01100, 11000, 10001, 00010.

f(00110,01100)=2;
f(00110,11000)=4;
f(00110,10001)=4;
f(00110,00010)=1.
Since in three substrings, f(b,c) is even, the answer is 3.

Vus can not find the answer for big strings. That is why he is asking you to help him.


Input

The first line contains a binary string a (1≤|a|≤106) — the first string.

The second line contains a binary string b (1≤|b|≤|a|) — the second string.


Output

Print one number — the answer.


Solution 1

这是我在考场上想出来的做法,但是写挂了

考虑串b移动之后会发生什么
例如
00110 ->
*00110
可以发现对于没移动的之前的第 i i i位,如果 i − 1 i-1 i−1位和 i i i位相同,那么移动后在 i i i这个位置上对答案的贡献是不会变的。
那么考虑不相同的时候假设第 i i i位是 0 0 0现在匹配到 1 1 1, i − 1 i-1 i−1位是 1 1 1那么移动后在 i i i这个位置上对答案的贡献是 − 1 -1 −1。
如果第 i i i位匹配到 0 0 0,那么移动后对答案的贡献就是 + 1 +1 +1
如果第 i i i是 1 1 1情况类似。
也就是如果 b b b串 i i i位和 i − 1 i-1 i−1位不一样,每移动一次对答案就会有一个^1的贡献(答案只考虑奇偶)
对b串求一次这个

int trans = 0;
for(int i=1;i<n;i++){trans ^= (str[i]-'0')^(str[i+1]-'0');
}


但是 b b b串移动之后,答案异或上b串的 t r a n s trans trans后只是更新了蓝色部分对答案的贡献。
还需要手动更新红色和绿色。

感觉我说的有点乱,可以看代码理解一下。
ps:b串的 t r a n s trans trans就是第一个异或最后一个,我也不知道为什么这么神奇。

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e6;
char s1[MAXN],s2[MAXN];
int n,m;
int main(){scanf("%s",s1+1);scanf("%s",s2+1);n=strlen(s1+1);m=strlen(s2+1);int flag = 0;flag ^= s2[1] ^ s2[m];int ans = 0;int tmp = 0;for(int i=1;i<=m;i++){if(s1[i] != s2[i])tmp ^= 1;}if(!tmp) ans ++;int point = m;while(point < n){point ++;tmp ^= flag;if(s1[point-m]!=s2[1])tmp ^= 1;if(s1[point] != s2[m]){tmp ^= 1;}if(!tmp){ans ++;}}cout<<ans;return 0;
}

Solution 2

我在结束之后 O r z Orz Orz了一下其他人的代码
发现了这个做法
考虑两个等长的 0 / 1 0/1 0/1串 a , b a,b a,b, a a a中有 s a s_a sa​个 1 1 1, b b b中有 s b s_b sb​个 1 1 1
那么这两个串不相同的位置的个数的就行就是 s a + s b s_a+s_b sa​+sb​的奇偶性
为什么?
先考虑只有 0 0 0和 1 1 1匹配和 0 0 0和 0 0 0匹配,显然正确,并且不同的个数就是 s a + s b s_a+s_b sa​+sb​
因为如果有多个 1 1 1匹配 1 1 1,那么不同的个数就是 s a + s b − k ∗ 2 s_a+s_b-k*2 sa​+sb​−k∗2减掉的数是 2 2 2的倍数,不改变奇偶性。
看完之后感觉自己是个zz


Solution 3

这不是个fft板子题吗

Codeforces #571 C Vus the Cossack and Strings相关推荐

  1. 【 CF1186D,E,F】Vus the Cossack and Numbers/Vus the Cossack and a Field/Vus the Cossack and a Graph

    太ex了,哭了哭了orz 后面两道平均一道花了我一天啊! 文章目录 D:Vus the Cossack and Numbers 题意翻译 题解 代码实现 E:Vus the Cossack and a ...

  2. Codeforces Round #313 (Div. 1) B. Equivalent Strings

    Equivalent Strings Problem's Link:   http://codeforces.com/contest/559/problem/B  Mean: 给定两个等长串s1,s2 ...

  3. 【CodeForces - 289C】Polo the Penguin and Strings (水题,字符串,思维构造,有坑)

    题干: Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wa ...

  4. CodeForces - 336D Vasily the Bear and Beautiful Strings(dp+组合数学)

    题目链接:点击查看 题目大意:给出一个 01 字符串,规定求值的过程如下: 每次选择末尾的两个数字: 如果为 0 0 ,那么替换成一个 1 否则替换成一个 0 循环往复,直至只剩一个数字位置,剩下的数 ...

  5. SCAU-春季训练-不应该啊(怎么这么菜。。。)

    2021/3/14 春季训练2(难度div2d) 反思:(赛前,看什么crt,赛时满脑子都是线性方程组,....................................) 最近表现都不太好.. ...

  6. 南昌不翻车 Codeforces Round #571 (Div. 2) C,D

    http://codeforces.com/contest/1186 C:(挺好的思维题) 题目大意:给俩串,A和B,然后A的每一个B子串,有一个价值,就是和B不同的数目,然后让统计偶数的代价有多少个 ...

  7. SCAU2021春季个人排位赛第七场 (部分题解))

    A:折半搜索+二分    跟上星期一样的知识点 B:拓扑排序 C:里面知识点都经常考并且糅合在一起,非常好的一道题.并查集+树DP考虑边的贡献 D:扫描线  上星期知识点                ...

  8. 2019/7/18ACM集训

    2019-07-18 09:15:34 这个是练习刷的题 Vus the Cossack and Numbers Vus the Cossack has nn real numbers aiai. I ...

  9. linux系统怎么看时间,查看和修改linux系统时间

    一.查看和修改Linux的时区1. 查看当前时区 命令 : "date -R" 2. 修改设置Linux服务器时区方法 A 命令 : "tzselect" 方法 ...

  10. Educational Codeforces Round 12 C. Simple Strings 贪心

    C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves si ...

最新文章

  1. 数十家公司超10亿数据外泄,2019年数据安全不再“纸上谈兵”
  2. [0] OpenCV_Notes - 琐碎
  3. 如何根据ABAP类的一个方法名称,反查出这个类的名称
  4. Matplotlib学习---用matplotlib画误差线(errorbar)
  5. 恐龙的丁丁长什么样?它们是怎么啪啪啪的?这项研究网友看完直呼涨姿势.........
  6. Mysql 8.0 安装
  7. Myeclipse学习总结(10)——MyEclipse2014导入项目时The project was not built since its build问题
  8. Chapter 6. H.264/MPEG4 Part10
  9. c语言在中职的作用,C语言程序下的中职教学论文
  10. 2.13.PHP7.1 狐教程-【PHP 类】
  11. sql server 2000 打了sp4补丁包仍不能监听1433端口问题的解决
  12. 电子计算机断层扫描简称,计算机断层扫描技术(简称PET)
  13. 有没有开以修改服务器游戏数据,剑网3指尖江湖第二批服务器数据互通啦 来看看有没有你所在的大区...
  14. Python爬虫实战之12306抢票开源
  15. 趣图:看到网友晒了新抱枕,我也想换个新的了
  16. su:密码正确,但权限被拒绝
  17. IE提示“存储空间不足,无法完成此操作”的错误(彻底解决包括产生原因)...
  18. 我的ubuntu8.04安装经验
  19. 贝加莱工控机维修主板维修5PC600.SX01-00常见故障排查
  20. python爬取万方数据库,爬虫获取 js 动态数据 (万方数据库文献下载)

热门文章

  1. 【机器学习】1.逻辑回归模型(1)
  2. jetson tx2 上部署TensorRT模型推理
  3. 快速排序空间复杂度( O(logn)-o(N))
  4. Matlab 数组与矩阵
  5. Android问题之showDialog方法deprecated
  6. 实战PyQt5: 120-像素图QPixmap和QBitmap
  7. C#中tabControl1控件详细使用方法
  8. Linux下Opencv的安装
  9. oracle添加字段前先判断字段是否已存在
  10. IntelliJ IDEA 怎么全局搜索