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

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.

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 题目大意:根据字符串的逆序数,从小到大输出字符串。
思路:将字符串和它的逆序数联系起来,通过对它的逆序数从小到大排序,对字符串排序。。。用结构体解决,用sort函数排序。
 #include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; typedef struct{
char s[];
int num;
}DNA; //求一个字符串的逆序数
int InversionNumber(char *s, int n){
int num = ;
for(int i = ; i < n - ; i++)
for(int j = i + ; j < n; j++){
if(s[i] > s[j])
num++;
}
return num;
} bool cmp(DNA a, DNA b){
return a.num < b.num;
} int main(){
int n, m;
cin >> n >> m;
DNA *a = new DNA [m];
for(int i = ; i < m; i++){
cin >> a[i].s;
a[i].num = InversionNumber(a[i].s, n);
}
sort(a, a + m, cmp); for(int i = ; i < m; i++)
cout << a[i].s << endl;
return ;
}

												

poj 1007 DNA Sorting的更多相关文章

  1. [POJ 1007] DNA Sorting C++解题

        DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 77786   Accepted: 31201 ...

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

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

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

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

  4. poj 1007 DNA sorting (qsort)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95209   Accepted: 38311 Des ...

  5. poj 1007 DNA Sorting 解题报告

    题目链接:http://poj.org/problem?id=1007 本题属于字符串排序问题.思路很简单,把每行的字符串和该行字符串统计出的字母逆序的总和看成一个结构体.最后把全部行按照这个总和从小 ...

  6. POJ 1007 DNA Sorting(sort函数的使用)

    Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are ...

  7. POJ 1007 DNA sorting (关于字符串和排序的水题)

    #include<iostream>//写字符串的题目可以用这种方式:str[i][j] &str[i] using namespace std; int main() {int ...

  8. poj 107 DNA sorting

    关于Java的题解,也许效率低下,但是能解决不只是ACGT的序列字符串 代码如下: import java.util.*; public class Main { public static void ...

  9. poj 1007 (nyoj 160) DNA Sorting

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

随机推荐

  1. SharePoint Srver 2010 资源汇总

    转:http://bbs.winos.cn/thread-93681-1-1.html Microsoft SharePoint Server 2010 是适用于企业和网络的业务协作平台,可以帮助您通 ...

  2. ifconfig命令

    许多windows非常熟悉ipconfig命令行工具,它被用来获取网络接口配置信息并对此进行修改.Linux系统拥有一个类似的工具,也就是ifconfig(interfaces config).通常需 ...

  3. win7 64位 VS2010调试提示“ORA-12154: TNS: 无法解析指定的连接标识符”的解决方法

    这个问题刚刚遇到,花了半小时,记录下 环境: vs2010[32位]  oracle 10g[32位] 操作系统:windows 7  64位 解决步骤: 1.去网上下载“instantclient- ...

  4. [liu yanling]黑盒测试用例设计方法

    1. 概述 黑盒测试用例设计方法包括等价类划分法.边界值分析法.错误推测法.因果图法.判定表驱动法.正交试验设计法.功能图法等. 2. 等价类划分法 2.1.          概念 等价类划分法是把 ...

  5. The Donkey of Gui Zhou

    Problem Description There was no donkey in the province of Gui Zhou, China. A trouble maker shipped ...

  6. [NOIP2002]自由落体

    NOIp2002提高组 题目描述 在高为 H 的天花板上有 n 个小球,体积不计,位置分别为 0,1,2,….n-1.在地面上有一个小车(长为 L,高为 K,距原点距离为 S1).已知小球下落距离计算 ...

  7. bzoj 2754 [SCOI2012]喵星球上的点名(后缀数组)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2754 [题意] 每只喵有名姓,如果被老师点到名或姓的子串都要答道,但每只喵一次点名只答 ...

  8. spoj 7258 SUBLEX(SAM,名次)

    [题目链接] http://www.spoj.com/problems/SUBLEX/en/ [题意] 给定一个字符串,询问次序为k的子串. [思路] SAM,名次 建好SAM后求出每个结点根据tra ...

  9. Fixing ssh login long delay

    原文:http://injustfiveminutes.com/2013/03/13/fixing-ssh-login-long-delay/ For a long time I had a prob ...

  10. 归并排序,递归法,C语言实现。

    利用归并排序法对序列排序的示意图(递归法): 一.算法分析:利用递归的分治方法:1.将原序列细分,直到成为单个元素:2.在将分割后的序列一层一层地按顺序合并,完成排序.细分通过不断深入递归完成,合并通 ...