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. 1
  2. 10 6
  3. AACATGAAGG
  4. TTTTGGCCAA
  5. TTTGGCCAAA
  6. GATCAGATTT
  7. CCCGGGGGGA
  8. ATCGATGCAT
 
Sample Output
  1. CCCGGGGGGA
  2. AACATGAAGG
  3. GATCAGATTT
  4. ATCGATGCAT
  5. TTTTGGCCAA
  6. TTTGGCCAAA
 
记得大一暑假的时候看到这个题也是一脸的懵逼
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. struct node
  6. {
  7. char s[55];
  8. int num,p;
  9. }q[1010];
  10. bool cmp(node s1,node s2)
  11. {
  12. if(s1.p==s2.p)
  13. return s1.num<s2.num;
  14. return s1.p<s2.p;
  15. }
  16. int main()
  17. {
  18. int t;
  19. scanf("%d",&t);
  20. while(t--)
  21. {
  22. int n,m;
  23. scanf("%d%d",&n,&m);
  24. for(int i=0;i<m;i++)
  25. {
  26. scanf("%s",q[i].s);
  27. q[i].num=i;
  28. q[i].p=0;
  29. for(int j=0;j<n;j++)
  30. {
  31. for(int k=j+1;k<n;k++)
  32. {
  33. if(q[i].s[j]>q[i].s[k])
  34. {
  35. q[i].p++;
  36. }
  37. }
  38. }
  39. }
  40. sort(q,q+m,cmp);
  41. for(int i=0;i<m;i++)
  42. printf("%s\n",q[i].s);
  43. }
  44. return 0;
  45. }

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. Python使用Flask框架,结合Highchart,自定义图表样式主题

    参考链接:https://www.highcharts.com.cn/docs/themes 1.使用官方提供的主题js文件,只需要在 highcharts.js 后引入对应的文件即可,不用修改原有的 ...

  2. LINUX:Contos7.0 / 7.2 LAMP+R 下载安装Apache篇

    文章来源:http://www.cnblogs.com/hello-tl/p/7568803.html 更新时间:2017-09-21 15:38 简介 LAMP+R指Linux+Apache+Mys ...

  3. LINUX系统---中级相关操作和知识

    LINUX系统的中级,来搞一些LINUX安全相关的东西,还有在公司生成中长搞的集群. RHCS集群 什么是高可用 什么是热备 什么是分布式

  4. python 列表(二)

     列表的其他操作 count 用于统计列表中某个元素出现的次数 Eg: extend 把一个列表添加到另一个列表里面 Index 输出元素的位置即根据内容索引位置 Reverse 把列表元素的位置倒过 ...

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

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

  6. web环境搭建

    [服务器] 硬件设备---计算机 软件 [作用] 作为web服务器运行.可以管理web项目 [目录说明] bin :存放各类可以执行文件,如:startup.bat conf:存放各类配置文件,常用配 ...

  7. QueryParser

    [概述] 其他工具类使用比较方便,但不够灵活.QueryParser也实现了较多的匹配方式. [QueryParser的应用] /** * 使用QueryParser进行查询 * @throws Pa ...

  8. 61. mybatic insert异常:BindingException: Parameter 'name' not found【从零开始学Spring B】

    mybatic insert异常:BindingException: Parameter 'name' not found [从零开始学习Spirng Boot-常见异常汇总] 异常信息如下: nes ...

  9. ORACLE审计小结

    ORACLE审计小结 1.什么是审计 审计(Audit)用于监视用户所执行的数据库操作,并且Oracle会将审计跟踪结果存放到OS文件(默认位置为$ORACLE_BASE/admin/$ORACLE_ ...

  10. [luoguP1868] 饥饿的奶牛(DP)

    传送门 先把所有区间按照左端点排序 f[i]表示区间0~i的最优解 #include <cstdio> #include <iostream> #include <alg ...