DNA Sorting(DNA排序)

花落北城 2013-06-13 09:02:15
求大神用java搞定,一定要是java啊,谢啦。

1 第一题
 Description
One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are out of order with respect to each other. For instance, in the letter sequence ``DAABEC'', this measure is 5, since D is greater than four letters to its right and E is greater than one letter to its right. This measure is called the number of inversions in the sequence. The sequence ``AACEDGG'' has only one inversion (E and D)---it is nearly sorted---while the sequence ``ZWQM'' has 6 inversions (it is as unsorted as can be---exactly the reverse of sorted).

You are responsible for cataloguing a sequence of DNA strings (sequences containing only the four letters A, C, G, and T). However, you want to catalog them, not in alphabetical order, but rather in order of ``sortedness'', from ``most sorted'' to ``least sorted''. All the strings are of the same length. (一个序列有一个度量的方法,比如“DAABEC”的度量就是5,首先D比它右边的四个字母大,而E比它右边的一个字母大,其余字母没有比自己右边字母大则为0,加起来就是5啦,本程序就是实现将多个字符串按这种度量方式从小排到大)
 Input
The first line contains two integers: a positive integer n (0 < n <= 50) giving the length of the strings; and a positive integer m (0 < m <= 100) giving the number of strings. These are followed by m lines, each containing a string of length n.
 Output
Output the list of input strings, arranged from ``most sorted'' to ``least sorted''. Since two strings can be equally sorted, then output them according to the orginal order.
 Sample Input
10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT

Sample Output

CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA
2 第二题
 Description
An ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from smallest to largest. For example, the sorted sequence A, B, C, D implies that A < B, B < C and C < D. in this problem, we will give you a set of relations of the form A < B and ask you to determine whether a sorted order has been specified or not.
 Input
Input consists of multiple problem instances. Each instance starts with a line containing two positive integers n and m. the first value indicated the number of objects to sort, where 2 <= n <= 26. The objects to be sorted will be the first n characters of the uppercase alphabet. The second value m indicates the number of relations of the form A < B which will be given in this problem instance. Next will be m lines, each containing one such relation consisting of three characters: an uppercase letter, the character "<" and a second uppercase letter. No letter will be outside the range of the first n letters of the alphabet. Values of n = m = 0 indicate end of input.
 Output
For each problem instance, output consists of one line. This line should be one of the following three:

Sorted sequence determined after xxx relations: yyy...y.
Sorted sequence cannot be determined.
Inconsistency found after xxx relations.

where xxx is the number of relations processed at the time either a sorted sequence is determined or an inconsistency is found, whichever comes first, and yyy...y is the sorted, ascending sequence. (本程序要求根据给出的字母之间的大小关系,来进行排序,输出有三种形式:1、Sorted sequence determined after xxx relations: yyy...y. 表示在遍历了xxx个“<”号后,得到了字母的排序为yyy...y;2、Sorted sequence cannot be determined.表示根据给出的字母的大小关系无法得出字母的排列顺序;3、 Inconsistency found after xxx relations.表示给出的字母大小关系是冲突的,比如:A<B、B<A;下面会对实例进行具体说明)
Sample Input
4 6(4表示有四个字母,6表示“<”的个数,即行数;下面是ABCD四个字母的大小关系)
A<B
A<C
B<C
C<D
B<D
A<B
3 2(3表示有3个字母,2表示“<”的个数,即行数;)
A<B
B<A
26 1(26表示有26个字母,1表示“<”的个数,即行数;)
A<Z
0 0(00表示结束)
 Sample Output
Sorted sequence determined after 4 relations: ABCD.(表示在遍历了前四个“<”号后,得出字母顺序为:ABCD)
Inconsistency found after 2 relations.(表示在遍历了2个“<”号后,得出字母关系冲突)
Sorted sequence cannot be determined.(表示无法得出字母顺序)
3 第三题

 Description
A certain prison contains a long hall of n cells, each right next to each other. Each cell has a prisoner in it, and each cell is locked.
One night, the jailer gets bored and decides to play a game. For round 1 of the game, he takes a drink of whiskey,and then runs down the hall unlocking each cell. For round 2, he takes a drink of whiskey, and then runs down the
hall locking every other cell (cells 2, 4, 6, ?). For round 3, he takes a drink of whiskey, and then runs down the hall. He visits every third cell (cells 3, 6, 9, ?). If the cell is locked, he unlocks it; if it is unlocked, he locks it. He
repeats this for n rounds, takes a final drink, and passes out.
Some number of prisoners, possibly zero, realizes that their cells are unlocked and the jailer is incapacitated. They immediately escape.
Given the number of cells, determine how many prisoners escape jail.(一个狱卒喝醉酒后,进行一个游戏,游戏规则为:第一轮他打开所有牢房的锁(开始牢房都是锁着的),牢房个数假设为n,第二轮他锁上第2*m(2、4、6、8….)个牢房的锁,第三轮他走到第3*m(3、6、9、12….)个牢房前,如果这个牢房锁着的就打开,如果这个牢房是开着的就锁上,就这样循环n轮,要求输出最后打开的牢房数)(个人理解就是第n轮游戏,狱卒就走到第n*m个牢房前,n*m是一个能被n整除的数,若该牢房是锁着的就打开,是开着的就锁上)
 Input
The first line of input contains a single positive integer. This is the number of lines that follow. Each of the following lines contains a single integer between 5 and 100, inclusive, which is the number of cells n.
 Output
For each line, you must print out the number of prisoners that escape when the prison has n cells.
 Sample Input
2(表示行数)
5(表示有5个牢房,进行了5轮游戏)
100(表示有100个牢房,进行了100轮游戏)
Sample Output
2(表示最后打开的牢房数为2个)
10(表示最后打开的牢房数为10个)



...全文
107 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

50,528

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧