DNA Sorting

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 2357    Accepted Submission(s): 1158

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
 
记得大一暑假的时候看到这个题也是一脸的懵逼
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
char s[55];
int num,p;
}q[1010];
bool cmp(node s1,node s2)
{
if(s1.p==s2.p)
return s1.num<s2.num;
return s1.p<s2.p;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)
{
scanf("%s",q[i].s);
q[i].num=i;
q[i].p=0;
for(int j=0;j<n;j++)
{
for(int k=j+1;k<n;k++)
{
if(q[i].s[j]>q[i].s[k])
{
q[i].p++;
}
}
}
}
sort(q,q+m,cmp);
for(int i=0;i<m;i++)
printf("%s\n",q[i].s);
}
return 0;
}

hdoj--1379--DNA Sorting(排序水题)的更多相关文章

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

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

  2. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  3. HDOJ(HDU) 1859 最小长方形(水题、、)

    Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内 ...

  4. HDU排序水题

    1040水题; These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fa ...

  5. PAT甲题题解-1012. The Best Rank (25)-排序水题

    排序,水题因为最后如果一个学生最好的排名有一样的,输出的课程有个优先级A>C>M>E那么按这个优先级顺序进行排序每次排序前先求当前课程的排名然后再与目前最好的排名比较.更新 至于查询 ...

  6. PAT甲题题解-1062. Talent and Virtue (25)-排序水题

    水题,分组排序即可. #include <iostream> #include <cstdio> #include <algorithm> #include < ...

  7. HDOJ/HDU 2560 Buildings(嗯~水题)

    Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...

  8. HDU 1379:DNA Sorting

    DNA Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  9. hdu1106 排序水题

    Problem Description 输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以‘0’开头,这些头部的‘0’应该被忽略掉,除非这个整 ...

随机推荐

  1. PHP:图片上传

    文章来源:http://www.cnblogs.com/hello-tl/p/7593033.html <?php class TL_Update_File{ private $file = n ...

  2. stark组件之显示页面内容搭建(六)

    之前主要介绍了前端页面list_fiter功能的显示,但是list_display功能的展示并没有过多介绍,这里介绍一下是如何实现的. 可以看到凡是蓝线圈起来的都是通过字段名反射一个个取出来的,红线的 ...

  3. python_字符串常用方法

    1.切片就是通过索引(索引:索引:步长)截取字符串的一段,形成新的字符串(原则就是顾头不顾腚). a = 'ABCDEFGHIJK' print(a[0:3]) # print(a[:3]) 从开头开 ...

  4. 【04】 CSS开发注意事项

    [04] CSS注意事项 1. 页面编码规范 1.1. 统一使用 UTF-8 编码,用@charset "utf-8"指定页面编码. 1.2. 全局字体设置: windows 7系 ...

  5. linux & command line & console & logs

    linux & command line & console & logs how to get the logs form linux command console htt ...

  6. noip模拟赛 数颜色

    分析:高级数据结构学傻了.....一眼看上去觉得是莫队,发现带修改,于是分块,由于写的常数很大,只有70分. 正解很简单,记录下颜色为c的每只兔子的位置,每次二分找这个区间有多少只这种颜色的兔子就可以 ...

  7. node.js里的buffer常见操作,copy,concat等实例讲解

    //通过长度构建的buffer内容是随机的 var buffer=new Buffer(100); console.log(buffer); //手动清空buffer,一般创建buffer不会清空 b ...

  8. 新vim配置文件

    "******************************************************特殊设置************************************ ...

  9. linux ftp服务器搭建

    作为服务器的机器IP:192.168.124.129  主机名:Centos 操作系统:CentOS 5.5 需求:匿名用户可以下载公共目录里边内容,本地用户登录有rwx权限 软件安装 1.  准备测 ...

  10. Core java for impatient 笔记

    类比c++来学习! 1.在java 中变量不持有对象,变量持有的是对象的引用,可以把变量看做c++中的只能指针,自动管理内存 需要手动初始化(否则就是空指针!) 2.final 相当于c++中的con ...