题干:

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

题目大意:

输入n个长度为m的DNA序列,把他们按照逆序数从小到大稳定排序输出。定义“稳定排序”就是当序列中出现A1==A2时,排序前后A1与A2的相对位置不发生改变。(n<=50 , m<=100)

解题报告:

跟这题差不多。【HihoCoder - 1550】顺序三元组。就是找到枚举每一个关键元素然后求和就行。

(好像正解是分治?)

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char maze[105][55];
int num[105];
int a[105],c[105],g[105],t[105];
struct Node {int val,pos;Node(){}Node(int val,int pos):val(val),pos(pos){}
} node[105];
bool cmp(const Node & a, const Node & b) {return a.val < b.val;
}
int main()
{int n,m;cin>>m>>n;//n行m列for(int i = 1; i<=n; i++) {scanf("%s",maze[i]+1);} for(int i = 1; i<=n; i++) {for(int j = 1; j<=m; j++) {if(maze[i][j] == 'A') {a[i]++;num[i] += c[i] + g[i] + t[i];}else if(maze[i][j] == 'C') {c[i]++;num[i] += g[i] + t[i];}else if(maze[i][j] == 'G') {g[i]++;num[i] += t[i];}else t[i]++;}}
//  for(int i = 1; i<=n; i++) printf("%d\n",num[i]);for(int i = 1; i<=n; i++) {node[i] = Node(num[i],i);}sort(node+1,node+n+1,cmp);
//  for(int i = 1; i<=n; i++) {
//      printf("%d  %d\n",node[i].pos,node[i].val);
//  }for(int i = 1; i<=n; i++) {printf("%s\n",maze[node[i].pos] + 1);}return 0 ;
}

这题用逆序数也可以搞一发?回头试试。类似HDU - 5775和OpenJ_Bailian - 2299

*【 POJ - 1007 】DNA Sorting(枚举,类似三元组找第二元问题)相关推荐

  1. POJ 1007 DNA Sorting

    按照字符串的逆序排序. /*Accepted 100K 16MS C++ 863B 2012-08-03 08:30:48*/ #include<stdio.h> #include< ...

  2. 1007:DNA Sorting

    总时间限制: 1000ms 内存限制: 65536kB 描述 One measure of ``unsortedness'' in a sequence is the number of pairs ...

  3. POJ 1007 DNA排序解题

    题目链接 http://poj.org/problem?id=1007 C++代码实现 #include<string> #include<iostream> using na ...

  4. POJ 1007 解题分析

    Technorati 标签: ACM,POJ 题目描述 题目链接:POJ 1007 DNA Sorting DNA Sorting Time Limit: 1000MS Memory Limit: 1 ...

  5. DNA Sorting(OpenJ_Bailian - 1007)

    B - DNA Sorting 来源: OpenJ_Bailian - 1007 Time limit:1000 ms           Memory limit:65536 kB OS:Linux ...

  6. POJ1007 DNA Sorting中英对照翻译与参考解答

    POJ1007 DNA Sorting 传送门:POJ 1007 关键词: 水题.排序 Description One measure of ``unsortedness'' in a sequenc ...

  7. DNA Sorting(排序)

    欢迎参加--BestCoder周年纪念赛(高质量题目+多重奖励) DNA Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  8. 算法:POJ1007 DNA sorting

    这题比较简单,重点应该在如何减少循环次数. package practice;import java.io.BufferedInputStream; import java.util.Map; imp ...

  9. POJ1007 UVA612 UVALive5414 ZOJ1188 HDU1379 Bailian4086 DNA Sorting【排序+逆序数】

    DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110791 Accepted: 44366 Descri ...

最新文章

  1. 对服务器文件夹写,服务器文件夹写入权限设置
  2. apache2.4.9 开启path_info访问_浅淡flask在win下用Apache24及mod_wsgi部署的那些坑
  3. python扫描端口脚本_Python实现的端口扫描功能示例
  4. 深入struts2.0(七)--ActionInvocation接口以及3DefaultActionInvocation类
  5. 超融合与传统架构真正的区别在哪?
  6. Exchange2010恢复已禁用邮箱后用户登录会出错
  7. android 城市列表数据,用RecyclerView写的城市列表
  8. java什么是类和对象,Java类和对象的概念
  9. Linux安装中遇到如下错误提示:"cannot find appropriate C++ compiler on this system"
  10. jqGrid中时间控件input的值赋给点开后的laydate控件
  11. 45个python入门案例_给Python小白看的10个使用案例,入门Python就在这里了
  12. 制度罚则-- 日志规范
  13. 微信小程序仿记事本,带下划线,自动换行,高度自增
  14. uni-app 图片自适应视图容器
  15. 当前时间转换成日期格式
  16. 用好HugePage,告别Linux性能故障
  17. Android studio File Explorer sdcard文件怎么访问
  18. MP4视频太大怎么在线压缩
  19. 江苏省对口单招分数线计算机,2021年江苏省对口单招分数线公布 江苏省对口单招省控线出炉...
  20. 信息学奥赛一本通 题解目录

热门文章

  1. 第九章 隐马尔科夫模型HMM
  2. [Leetcode][第81题][JAVA][N皇后问题][回溯算法]
  3. xadsafe做暗刷_手把手教你如何去掉网吧广告之PUBWin2015_XADSAFE
  4. 平板电脑可以插u盘吗_电视TV盒子安装app的六个方法,u盘/电脑/手机都可以安装...
  5. 华为鸿蒙系统智能手机_余承东再度确认:鸿蒙系统将适配到华为手机上
  6. mysql集群重启报错lock_CentOS7.2 下 MySQL 之 PXC 集群部署【Docker+单机多节点】
  7. python3导入模块原理_Python模块导入机制与规范
  8. php 判断修改成功,PHP判断文件是否被修改实例
  9. sqlite sqlite3_bind_int sqlite3_bind_text
  10. 编译mediastreamer2/ffmpeg/linphone(x86平台)