zoukankan      html  css  js  c++  java
  • HDU 1379:DNA Sorting

    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;
    }


  • 相关阅读:
    IDEA的Debug详解
    websocket学习(转载)
    Shiro授权及注解式开发
    Redis分布式缓存安装和使用
    JEESZ-SSO解决方案
    英语是学习Java编程的基础吗
    深入分析 ThreadLocal 内存泄漏问题
    这些JVM命令配置参数你知道吗?
    安全开发Java动态代理
    学java编程软件开发,非计算机专业是否能学
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989591.html
Copyright © 2011-2022 走看看