日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Circular Sequence UVA - 1584

發(fā)布時(shí)間:2024/4/30 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Circular Sequence UVA - 1584 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

原題及翻譯

Some DNA sequences exist in circular forms as in the following figure, which shows a circular sequence “CGAGTCAGCT”, that is, the last symbol “T” in “CGAGTCAGCT” is connected to the first symbol “C”.
如下圖所示,一些DNA序列以圓形存在,顯示了一個(gè)圓形序列“cgagtacgt”,即“cgagtacgt”中的最后一個(gè)符號(hào)“t”與第一個(gè)符號(hào)“c”相連。

We always read a circular sequence in the clockwise direction.
我們通常在順時(shí)針?lè)较蜃x取一個(gè)圓形序列。
Since it is not easy to store a circular sequence in a com- puter as it is, we decided to store it as a linear sequence.
由于在計(jì)算機(jī)中存儲(chǔ)循環(huán)序列并不容易,因此我們決定將其存儲(chǔ)為線性序列。
However, there can be many linear sequences that are ob- tained from a circular sequence by cutting any place of the circular sequence.
然而,通過(guò)切割圓形序列的任何位置,可以從圓形序列中獲得許多線性序列。
Hence, we also decided to store the linear sequence that is lexicographically smallest among all linear sequences that can be obtained from a circular sequence.
因此,我們還決定存儲(chǔ)線性序列,它在所有可以從循環(huán)序列中獲得的線性序列中在詞典上是最小的。
Your task is to find the lexicographically smallest sequence from a given circular sequence.
您的任務(wù)是從給定的循環(huán)序列中查找詞典上最小的序列。
For the example in the figure,
對(duì)于圖中的例,
the lexicographically smallest sequence is “AGCTCGAGTC”.
詞典最小的序列是“agctcgagtc”。
If there are two or more linear sequences that are lexicographically smallest, you are to find any one of them (in fact, they are the same).
如果有兩個(gè)或兩個(gè)以上的線性序列在詞典上是最小的,那么您可以找到它們中的任何一個(gè)(事實(shí)上,它們是相同的)。

Input

輸入
The input consists of T test cases.
輸入由T測(cè)試用例組成。
The number of test cases T is given on the first line of the input file.
一行給出測(cè)試用例數(shù)t。
Each test case takes one line containing a circular sequence that is written as an arbitrary linear sequence.
在輸入文件的第每個(gè)測(cè)試用例采用一行,其中包含一個(gè)循環(huán)序列,該循環(huán)序列被寫(xiě)成一個(gè)任意的線性序列。
Since the circular sequences are DNA sequences, only four symbols, ‘A’, ‘C’, ‘G’ and ‘T’, are allowed.
由于圓形序列是DNA序列,因此只允許使用“A”、“C”、“G”和“T”四個(gè)符號(hào)。
Each sequence has length at least 2 and at most 100.
每個(gè)序列的長(zhǎng)度至少為2,最多為100。

Output

輸出
Print exactly one line for each test case.
每個(gè)測(cè)試用例只打印一行。
The line is to contain the lexicographically smallest sequence for the test case.
該行包含測(cè)試用例的詞典最小序列。

Sample Input

2
CGAGTCAGCT CTCC

Sample Output

AGCTCGAGTC CCCT

題目理解

長(zhǎng)度為n的環(huán)狀序列有n種表示方法,分別為從某個(gè)位置開(kāi)始順時(shí)針得到。其中,字典序最小的稱(chēng)為“最小表示”。
輸入一個(gè)長(zhǎng)度為n(n<=100)的環(huán)狀DNA串(只包含A,C,G,T這4種字符)的一種表示法,你的任務(wù)是輸出該環(huán)狀串的最小表示。

思路

所謂的字典序,就是字符串在字典中的順序。

一般地,對(duì)于兩個(gè)字符串,從第一個(gè)字符開(kāi)始比較,當(dāng)某一個(gè)位置的字符不同時(shí),該位置字符較小的串,字典序較小;如果其中一個(gè)字符串已經(jīng)沒(méi)有更多字符,但另一個(gè)字符串還沒(méi)結(jié)束,則較短的字符串的字典序較小。

字典序的可以推廣到任意序列。

代碼

#include <stdio.h> #include <string.h> #define maxn 105 int less(const char* s,int p,int q) {int n=strlen(s);for(int i=0;i<n;i++){if(s[(p+i)%n]!=s[(q+i)%n]){return s[(p+i)%n]<s[(q+i)%n];}}return 0; } int main() {int t;char s[maxn];scanf("%d",&t);while(t--){scanf("%s",s);int ans=0;int n=strlen(s);for(int i=1;i<n;i++){if(less(s,i,ans)) ans=i;}for(int i=0;i<n;i++){putchar(s[(i+ans)%n]);}putchar('\n');}return 0; }

總結(jié)

以上是生活随笔為你收集整理的Circular Sequence UVA - 1584的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。