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. 笔试算法题(38):并查集(Union-Find Sets)

    议题:并查集(Union-Find Sets) 分析: 一种树型数据结构,用于处理不相交集合(Disjoint Sets)的合并以及查询:一开始让所有元素独立成树,也就是只有根节点的树:然后根据需要将 ...

  2. 零基础入门学习Python(5)--闲聊之Python的数据类型

    前言 本次主要闲聊一下python的一些数值类型,整型(int),浮点型(float),布尔类型(bool),还有e记法(科学计数法),也是属于浮点型. 数值类型介绍 整型 整型就是我们平时所说的整数 ...

  3. 使用 PHP + shell 生成 一键设置权限的脚本。

    linux 系统 支持PHP脚本一键设置环境.shell脚本一键设置环境.那么 我今天 使用 PHP  + shell 生成 一键设置权限的脚本. 举例子:linux服务器 一键配置discuz网站环 ...

  4. jQuery的ready与js的load事件的区别

    摘自:http://www.cnblogs.com/see7di/archive/2011/07/15/2239677.html 为了理解这两个事件的异同,读者应该先了解HTML文档加载的顺序. DO ...

  5. jsp+servlet+mysql增删改查

    用的IntelliJ IDEA开发的,jdk1.8 1 首先是项目结构,如下图所示 2看各层的代码 首先是web.xml <?xml version="1.0" encodi ...

  6. c#读取MySQL数据表中的内容

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  7. mongodb shell 无法删除问题

    1.MongoDB Shell中退格键使用的问题. 利用SecureCRT工具访问linux的时候,在使用MongoDB的交互式shell的时候,退格键(Backspace)无法使用,导致无 法修改输 ...

  8. HDU 5642 King's Order【数位dp】

    题目链接: http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=677&pid=1003 题意: 求长度为n的序列 ...

  9. org.springframework.amqp.AmqpIOException: java.net.UnknownHostException: guest解决

    org.springframework.amqp.AmqpIOException: java.net.UnknownHostException: guest 由于在yml文件中配置的时候误将passw ...

  10. JAVA初级复习知识点归纳

    JDK的安装: 下载.安装 配置环境变量 a) path:.;%JAVA_HOME%\bin; b) JAVA_HOME:JDK的安装目录 c) classpath JDK和JRE和JVM: JAVA ...