原题及翻译

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序列以圆形存在,显示了一个圆形序列“cgagtacgt”,即“cgagtacgt”中的最后一个符号“t”与第一个符号“c”相连。

We always read a circular sequence in the clockwise direction.
我们通常在顺时针方向读取一个圆形序列。
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.
由于在计算机中存储循环序列并不容易,因此我们决定将其存储为线性序列。
However, there can be many linear sequences that are ob- tained from a circular sequence by cutting any place of the circular sequence.
然而,通过切割圆形序列的任何位置,可以从圆形序列中获得许多线性序列。
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.
因此,我们还决定存储线性序列,它在所有可以从循环序列中获得的线性序列中在词典上是最小的。
Your task is to find the lexicographically smallest sequence from a given circular sequence.
您的任务是从给定的循环序列中查找词典上最小的序列。
For the example in the figure,
对于图中的例,
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).
如果有两个或两个以上的线性序列在词典上是最小的,那么您可以找到它们中的任何一个(事实上,它们是相同的)。

Input

输入
The input consists of T test cases.
输入由T测试用例组成。
The number of test cases T is given on the first line of the input file.
一行给出测试用例数t。
Each test case takes one line containing a circular sequence that is written as an arbitrary linear sequence.
在输入文件的第每个测试用例采用一行,其中包含一个循环序列,该循环序列被写成一个任意的线性序列。
Since the circular sequences are DNA sequences, only four symbols, ‘A’, ‘C’, ‘G’ and ‘T’, are allowed.
由于圆形序列是DNA序列,因此只允许使用“A”、“C”、“G”和“T”四个符号。
Each sequence has length at least 2 and at most 100.
每个序列的长度至少为2,最多为100。

Output

输出
Print exactly one line for each test case.
每个测试用例只打印一行。
The line is to contain the lexicographically smallest sequence for the test case.
该行包含测试用例的词典最小序列。

Sample Input

2
CGAGTCAGCT CTCC

Sample Output

AGCTCGAGTC CCCT

题目理解

长度为n的环状序列有n种表示方法,分别为从某个位置开始顺时针得到。其中,字典序最小的称为“最小表示”。
输入一个长度为n(n<=100)的环状DNA串(只包含A,C,G,T这4种字符)的一种表示法,你的任务是输出该环状串的最小表示。

思路

所谓的字典序,就是字符串在字典中的顺序。

一般地,对于两个字符串,从第一个字符开始比较,当某一个位置的字符不同时,该位置字符较小的串,字典序较小;如果其中一个字符串已经没有更多字符,但另一个字符串还没结束,则较短的字符串的字典序较小。

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

代码

#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;
}

Circular Sequence UVA - 1584相关推荐

  1. (艾迪茉莉转圈圈~~找最小环)Circular Sequence UVA - 1584

    #include<iostream> #include<string.h> #include<stdio.h> using namespace std; char ...

  2. UVA1584 ​​​​​​​Circular Sequence【字符串】

    Circular Sequence UVA - 1584 题目传送门 题目大意:输入一个环形字符串,需输出其最小字典序的形式的字符串. AC代码: #include <cstdio> #i ...

  3. 【UVA/Codeforces】1584 Circular Sequence / 792B Counting-out Rhyme(就是一个圈儿...)

    https://vjudge.net/problem/UVA-1584 1584 Circular Sequence 输入一个字符串,可以以字符串中任意一个字母作为起始,输出字典序最小的那个字符串 两 ...

  4. 1584 - Circular Sequence

    Circular Sequence Some DNA sequences exist in circular forms as in the following figure, which shows ...

  5. UVA1584 UVALive3225 Circular Sequence【水题】

      Some DNA sequences exist in circular forms as in the following figure, which shows a circular sequ ...

  6. UVa1584 - Circular Sequence

    //UVa1584 - Circular Sequence //题目:给你一个环状串,输出它以某一位置为起点时得到最小字典序的串. //分析:从初位置到末位置每次更新字典序较小的起始位置 #inclu ...

  7. 例题3-6 环状序列(Circular Sequence)

    我的代码(vjudge AC): //Circular Sequence #include <stdio.h> #include <string.h> bool less(co ...

  8. 例题3-6 环状序列(Circular Sequence, ACM/ICPC Seoul 2004, UVa1584)

    长度为n的环状串有n种表示法,分别为从某 个位置开始顺时针得到.例如,图3-4的环状串 有10种表示: CGAGTCAGCT,GAGTCAGCTC,AGTCAGCTCG等.在这些表示法中,字典序最小的 ...

  9. 算法竞赛入门经典(第二版) | 程序3-10 生成元 (UVa1584,Circular Sequence)

    题目概述: 长度为n的环状串有n种表示法, 字典序最小的称为最小表示.输入一个长度为n(n<100)的环状字符串的一种表示方法,输出最小表示 . 如:CTCC 为环状字符串的一种表示方法,它的所 ...

最新文章

  1. BZOJ1192: [HNOI2006]鬼谷子的钱袋
  2. S3C6410的IROM启动模式
  3. python输入什么就输出什么_一文读懂Python的输入和输出
  4. 信息学奥赛一本通(C++)在线评测系统——基础(一)C++语言—— 1053:最大数输出
  5. java加密工作模式None_java加解密算法--对称加密工作模式
  6. python类似微信未读信息图片脚本
  7. Android:通过startActivityForResult方法来得到Activity的回传值
  8. matlab编程设计fir滤波器,用MATLAB设计FIR滤波器
  9. python寻找1000以内的阿姆斯特朗数
  10. springmvc请求返回一个字符_Spring MVC框架详解01
  11. OSChina 周日乱弹 —— 普通人如何面对持刀歹徒
  12. 深度学习-各类数据集汇总
  13. C++求出200以内的所有质数(素数),并按每行5个输出在屏幕上。
  14. html css blockquote,css之blockquote美化
  15. 解决显示“此图片来自微信公众平台未经允许不可引用”错误图片
  16. inl和dnl matlab_AD的一些指标——INL与DNL
  17. 折线迷你图怎么设置_Excel2013如何使用迷你图展示数据?
  18. 联通大数据携U10峰会而来……
  19. IoT大门上的鲁班锁:华为所铸的分布式安全
  20. SAP-MM 采购订单涉及的后台表

热门文章

  1. C#简单实现读取txt文本文件并分页存储到数组
  2. CentOS 7.2修改网卡名称
  3. 微信授权登录提示不能访问?
  4. 软件工程个人作业05
  5. 16、Windows API 服务
  6. 每日程序C语言28-有序数组插入元素
  7. Java黑皮书课后题第1章:1.7(求π的近似值)编写程序,显示4*(1-1/3+1/5-1/7+1/9-1/11【+1/13】)
  8. C语言学习之利用指针输出二维数组任一行任一列元素的值
  9. 【强烈推荐】程序猿们,九度Online Judge开始举办月赛啦!!会编程才是王道!!!!!
  10. N皇后问题的两个最高效的算法