ZCMU暑期训练四-E - Vus the Cossack and Strings
作者:互联网
Vus the Cossack has two binary strings, that is, strings that consist only of “0” and “1”. We call these strings aa and bb. It is known that |b|≤|a||b|≤|a|, that is, the length of bb is at most the length of aa.
The Cossack considers every substring of length |b||b| in string aa. Let’s call this substring cc. He matches the corresponding characters in bb and cc, after which he counts the number of positions where the two strings are different. We call this function f(b,c)f(b,c).
For example, let b=00110b=00110, and c=11000c=11000. In these strings, the first, second, third and fourth positions are different.
Vus the Cossack counts the number of such substrings cc such that f(b,c)f(b,c) is even.
For example, let a=01100010a=01100010 and b=00110b=00110. aa has four substrings of the length |b||b|: 0110001100, 1100011000, 1000110001, 0001000010.
f(00110,01100)=2f(00110,01100)=2;
f(00110,11000)=4f(00110,11000)=4;
f(00110,10001)=4f(00110,10001)=4;
f(00110,00010)=1f(00110,00010)=1.
Since in three substrings, f(b,c)f(b,c) is even, the answer is 33.
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 aa (1≤|a|≤1061≤|a|≤106) — the first string.
The second line contains a binary string bb (1≤|b|≤|a|1≤|b|≤|a|) — the second string.
Output
Print one number — the answer.
Examples
Input
01100010
00110
Output
3
Input
1010111110
0110
Output
4
Note
The first example is explained in the legend.
In the second example, there are five substrings that satisfy us: 10101010, 01010101, 11111111, 11111111.
题面给你两个串 a,b a长于b,b和a逐位异或运算看最后的奇偶;
思路:如果 模拟肯定T,用异或的性质,来储存奇偶;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 2000030;
char a[maxn],b[maxn];
int ans=0,sum=0;
int main(){
scanf("%s",a);
scanf("%s",b);
int len_a=strlen(a);
int len_b=strlen(b);
for(int i=0;i<len_b;i++){
ans=ans^a[i]^b[i];
}
if(ans%2==0)sum++;
for(int i=len_b;i<len_a;i++){
ans=ans^a[i-len_b]^a[i];
if(ans%2==0)sum++;
}
printf("%d\n",sum);
return 0;
}
标签:aa,string,int,ZCMU,00110,Vus,include,Cossack,strings 来源: https://blog.csdn.net/qq_43624815/article/details/96457079