HDU 1379:DNA Sorting
来源:互联网 发布:linux如何上传文件夹 编辑:程序博客网 时间:2024/05/22 00:34
DNA Sorting
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2329 Accepted Submission(s): 1145
Problem 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.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
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.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
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 (1 < 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''. If two or more strings are equally sorted, list them in the same order they are in the input file.
Sample Input
110 6AACATGAAGGTTTTGGCCAATTTGGCCAAAGATCAGATTTCCCGGGGGGAATCGATGCAT
Sample Output
CCCGGGGGGAAACATGAAGGGATCAGATTTATCGATGCATTTTTGGCCAATTTGGCCAAA
Source
East Central North America 1998
Recommend
Eddy | We have carefully selected several similar problems for you: 1328 1321 1062 1020 1073
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include <stdio.h>#include <algorithm>#include <iostream>#include<string.h>#include<math.h>using namespace std;struct DNA{ char c[55]; int data;} d[105];int nixu(char *c){ int k=0; int n=strlen(c); for(int i=0; i<n; i++) { for(int j=i+1; j<n; j++) if(c[i]>c[j])k++; } return k;}void paixu(int m){ for(int i=0; i<m; i++) for(int j=0; j<m-i-1; j++) if(d[j+1].data<d[j].data) { DNA a=d[j+1]; d[j+1]=d[j]; d[j]=a; }}int main(){ int t; cin>>t; while(t--) { int n,m; cin>>n>>m; getchar(); for(int i=0; i<m; i++) { scanf("%s",d[i].c); d[i].data=nixu(d[i].c); } paixu(m); for(int i=0; i<m; i++) puts(d[i].c); } return 0;}
1 0
- HDU 1379 DNA sorting
- hdu 1379 DNA Sorting
- HDU 1379:DNA Sorting
- hdu-1379 DNA Sorting
- hdu 1379 DNA Sorting
- HDU—— 1379 DNA Sorting
- hdu杭电 1379 DNA Sorting
- HDU 1379 DNA Sorting (水归并排序)
- HDU DNA Sorting
- DNA Sorting HDU
- Hdoj 1379 DNA Sorting
- hdoj 1379 DNA Sorting
- 1379 DNA Sorting
- POJ 1007 && HDU 1379 DNA Sorting(水~)
- 杭电 1379 DNA Sorting
- hdoj 1379 DNA Sorting【排序】
- DNA Sorting 1379 (字符串排序)
- 杭电1379DNA Sorting
- HDU 1205:吃糖果
- HDU 1071:The area
- 【jQuery入门】jQuery基础课程
- HDU 1009:FatMouse' Trade
- 最短路径
- HDU 1379:DNA Sorting
- JavaSE023_Java异常封装(自定义错误码和描述)
- 使用Spring实现读写分离(MySQL实现主从复制)
- ASP.NET应用程序与页面生命周期
- Yii - data exists update else insert
- Spring MVC程序中得到静态资源文件css,js,图片文件的路径
- OC--小知识总结
- IOException while loading persisted sessions: java.io.EOFException
- 开发Rpg maker第一弹