C. Vus the Cossack and Strings
1、总结:
真是太不仔细了,竟然将题目看错了,题目要求求出所有不同的字符个数为偶数的情况。
找规律可以发现只要子串1的个数的奇偶性与模板串的1的个数的奇偶性相同就说明有偶数个字符不同,所以用前缀和来做。
2、代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1e6+10;
char s1[maxn],s2[maxn];
int pre[maxn];
int main(void){
int n,m;
scanf("%s%s",s1+1,s2+1);
n = strlen(s1+1);
m = strlen(s2+1);
pre[0] = 0;
int tp = 0,ans = 0;
for(int i=1;i<=m;i++)
if(s2[i]=='1') tp++;
tp %= 2;
for(int i=1;i<=n;i++)
if(s1[i]=='1') pre[i] = pre[i-1]+1;
else pre[i] = pre[i-1];
for(int i=1,j=m;j<=n;j++,i++)
if((pre[j]-pre[i-1])%2==tp){
ans++;
}
printf("%d\n",ans);
return 0;
}