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.


 
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
1 10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT
 
Sample Output
CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA
 
Source
 
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;
}

HDU 1379:DNA Sorting的更多相关文章

  1. 算法:POJ1007 DNA sorting

    这题比较简单,重点应该在如何减少循环次数. package practice; import java.io.BufferedInputStream; import java.util.Map; im ...

  2. poj 1007:DNA Sorting(水题,字符串逆序数排序)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80832   Accepted: 32533 Des ...

  3. [POJ1007]DNA Sorting

    [POJ1007]DNA Sorting 试题描述 One measure of ``unsortedness'' in a sequence is the number of pairs of en ...

  4. DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏

    DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...

  5. poj 1007 (nyoj 160) DNA Sorting

    点击打开链接 DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 75164   Accepted: 30 ...

  6. [POJ] #1007# DNA Sorting : 桶排序

    一. 题目 DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95052   Accepted: 382 ...

  7. poj 1007 DNA Sorting

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95437   Accepted: 38399 Des ...

  8. DNA Sorting(排序)

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) DNA Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  9. HDU 1560 DNA sequence(DNA序列)

    HDU 1560 DNA sequence(DNA序列) Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K  ...

随机推荐

  1. 「 HDU P4734 」 F(x)

    # 题目大意 对于一个数 $x$,它的每一位数字分别是 $A_{n}A_{n-1}A_{n-2}\cdots A_{2}A_{1}$,定义其权重 $f(x)=\sum_{i=1}^{n}\left(A ...

  2. 2 SQL 查询基础

    2 查询基础 2-1 SELECT语句基础 通过SELECT语句查询并选取必要数据的过程称为匹配查询或查询(query). 子句是SQL语句的组成要素,是以SELECT或者FROM等作为起始的短语. ...

  3. 201621123082《Java程序设计》第1周学习总结

    1. 本周学习总结: 关键词: 了解Java语言的发展历史.了解Java语言的特点.JDK.JRE.JVM.eclipse等. 联系: JDK是提供给Java开发人员使用的一组工具,JDK包含JVM及 ...

  4. 86-Money Flow Index 资金流量指数指标.(2015.7.3)

    Money Flow Index 资金流量指数指标 计算: 1.典型价格(TP)=当日最高价.最低价与收盘价的算术平均值 2.货币流量(MF)=典型价格(TP)×N日内成交金额 3.如果当日MF> ...

  5. 程序包javax.servlet.http不存在

    在maven test项目时,出现错误: java:[7,26] 程序包javax.servlet.http不存在 原因:pom.xml中未引入javax.servlert-api相关的包 <d ...

  6. //……关于TCP三次握手与四次挥手

    TCP的概述 TCP把连接作为最基本的对象,每一条TCP连接都有两个端点,这种断点我们叫作套接字(socket),它的定义为端口号拼接到IP地址即构成了套接字,例如,若IP地址为192.3.4.16 ...

  7. python pip 安装一些包找不到的问题 Could not find a version that satisfies....

    有时我们使用下载python 自带的pip 安装一些工具包时,会报如下错误 找不到满意的版本,这时就是我们的pip可能需要升级了,所以使用 python -m pip install --upgrad ...

  8. java中使用Protobuf的实例(Demo)

    由于Protobuf受到推崇,故尝试采用protobuf来摒弃传统的xml进行传输数据. 首先,需要下载的关于Protobuf的文件: 1.到http://code.google.com/p/prot ...

  9. java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.views.login_jsp

    背景:SpringBoot的项目配置了对jsp的支持,走控制器就报这个错误.相关配置如下: <!-- JSP BEGIN --> <dependency> <groupI ...

  10. Codeforces908G. New Year and Original Order

    给n<=10^700,问1到n中每个数在各数位排序后得到的数的和.答案膜1e9+7. 一看就是数位DP啦..然而并没有什么思路.. 可以尝试统计n(i,j)表示数j在第i位的出现次数,知道了这个 ...