hihocoder#1052 Genetic Engineering

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.