C. Vus the Cossack and Strings

 

. 1  / * ******
 2  http://codeforces.com/contest/1186/problem/C 
. 3  that Italy: 0,1 to 2 strings, a string longer than the string b.
4  asked how many and a string length and the number of different character strings, etc. b is an even number of strings.
5  ideas: In a first compare a first string (denoted as a0) and a different number of characters b (denoted as ans0). Then in a second string (referred to as a1) will not compare a to b, but compared with the first string.
6  here divided into two cases: (1): do not control a1 [i] == a0 [i ] when; (because in this case, regardless of a0 [i] and b [i] are the same, a1 [i] and b [i] is the same case with the former)
 . 7                  (2): A1 [i] = A0 [i] records the case when the number (referred to as s1)!. (A1 [i] with just a0 [i] in the case of b [i] is opposite to the case of b [i]) is
 8                  if (ans0 + s1)% 2 == 0 in the string is one of the answer;
 9  then for any equal to a size of a to b in the end is not the answer string, we can (a different number of characters of the previous string in the string + number (2) of the case) is determined.
10  For any string, the number (2) of the case, it may be pretreated by 0 (1).                
11  *** * / 
12  
13 
14 #include<bits/stdc++.h>
15 using namespace std;
16 int s[1000009],ans[1000009];
17 int main()
18 {
19      string sa,sb;
20      int la,lb;
21      cin>>sa>>sb;
22      la=sa.size( ),lb=sb.size();
23      s[0]=0;
24      for(int i=1;i<la;i++)
25      {
26          if(sa[i]==sa[i-1])s[i]=s[i-1];
27          else s[i]=s[i-1]+1;
28      }
29      int k=0;
30      for(int i=0;i<lb;i++)
31      {
32          if(sa[i]!=sb[i])ans[lb-1]++;
33      }
34      if(ans[lb-1]%2==0)ans[lb-1]=0;
35      for(int i=lb;i<la;i++)
36      {
37           ans[i]=(ans[i-1]+s[i]-s[i-lb])%2;
38      }
39      int tans=0;
40      for(int i=lb-1;i<la;i++)
41      {
42          if(ans[i]==0) tans++;
43      }
44      cout<<tans<<endl;
45     return 0;
46 }

 

Guess you like

Origin www.cnblogs.com/yzxqq/p/11110914.html