Ring DNA sequence

Source: Internet
Author: User

Note:

A dna sequence is ring, which means that the sequence with N bases has n Representation Methods (assuming there is no repetition ). The N sequences have a minimum representation, which means that the Lexicographic Order of the sequence is the smallest (the Lexicographic Order means the size of the dictionary, such as ABC <ACB, B <BCD, EF <G)

 

Method: the size of the generated sequence can be compared from any two locations in a sequence. Then use this comparison method to find the minimum value.

# Include <iostream> using namespace STD; # define Max 105int lessthan (char s [], int P, int q) // The size of a sequence starting from P and starting from q {long Len = strlen (s); For (INT I = 0; I <Len; I ++) {If (s [(p + I) % Len]! = S [(q + I) % Len]) return s [(p + I) % Len] <s [(q + I) % Len]; // compare size} return 0;} int main () {int t; CIN> T; while (t --) {char s [Max]; CIN> S; long n = strlen (s); int flag = 0; For (INT I = 0; I <n; I ++) // It is equivalent to finding the smallest element in the array {If (lessthan (S, I, flag) Flag = I ;}for (INT I = 0; I <n; I ++) cout <s [(flag + I) % N]; cout <Endl ;}}

 

 

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.