Original title Address
Find a regular problem
If it is not, then the number of different digits is the number of times the change is required.
If the end-to-end intersection seems more complex, so look for patterns.
Suppose the string is this (the same string up and down, just to make it easier to describe the end-to-end part), so that the blue end-to-end part is the same:
Because it is a string, the dashed parts are the same.
That is, the middle Red box section is the same.
Because the blue and the end parts are the same, there are:
The dashed part is the same:
And at this point, we can get the same dashed part:
Finally, repeating this process, we divided the blue part into a follow-up link:
As you can see from the first step, the length of this cycle section is N-k
So, as long as the blue part is n-k for the length of the loop can satisfy the condition.
Code:
1#include <iostream>2#include <cstring>3 4 using namespacestd;5 6 intMain () {7 intT, K, N;8 Charstr[1024x768];9 TenCIN >>T; One while(t--) { ACIN >>str; -CIN >>K; -N =strlen (str); the intres =0; - - ifK2<=N) { - for(inti =0, j = n-k; J < N; J + +, i++) +Res + = Str[i]! = str[j]?1:0; -cout << Res <<Endl; + } A Else { at intLen = N-K; - for(inti =0; i < Len; i++) { - intcount[4] = {0}; - for(intj = i; J < N; J + =Len) { - if(Str[j] = ='A') -count[0]++; in Else if(Str[j] = ='T') -count[1]++; to Else if(Str[j] = ='C') +count[2]++; - Else if(Str[j] = ='G') thecount[3]++; * } $ intMaximum =0;Panax Notoginseng for(intj =0; J <4; J + +) { -Maximum =max (maximum, count[j]); theRes + =Count[j]; + } ARes-=maximum; the } +cout << Res <<Endl; - } $ } $ - return 0; -}
hihocoder#1052 Genetic Engineering