博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1007 DNA Sorting(排序--快排)
阅读量:6591 次
发布时间:2019-06-24

本文共 2181 字,大约阅读时间需要 7 分钟。

DNA Sorting
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 67603   Accepted: 26858

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 6AACATGAAGGTTTTGGCCAATTTGGCCAAAGATCAGATTTCCCGGGGGGAATCGATGCAT

Sample Output

CCCGGGGGGAAACATGAAGGGATCAGATTTATCGATGCATTTTTGGCCAATTTGGCCAAA

Source

 

#include 
#include
using namespace std;typedef struct{ string dna; int count;}DNA;DNA dna[101];int cmp(const void *a,const void *b){ DNA *aa = (DNA *)a; DNA *bb = (DNA *)b; return aa->count-bb->count;}int main(){ int n,m; char c; cin>>n>>m; for(int i = 0; i < m; i++) { cin>>dna[i].dna; dna[i].count = 0; for(int j = 0; j < n; j++) for(int k = j+1; k < n; k++) { if(dna[i].dna[j]>dna[i].dna[k]) dna[i].count++; } } qsort(dna,m,sizeof(dna[0]),cmp); for(int i = 0; i < m; i++) cout<
<

转载地址:http://oazio.baihongyu.com/

你可能感兴趣的文章
Shader 学习笔记 ---Depth of Field 介绍
查看>>
星级 评分
查看>>
通信协议之广播---recvfrom 放回客户端的ip地址第一次全为0.0.0.0
查看>>
php 常用函数
查看>>
oracle-3-子查询和常用函数
查看>>
item2
查看>>
云计算面临安全挑战
查看>>
C# 线程手册 第三章 使用线程 Monitor.TryEnter()
查看>>
分享11个超棒的移动应用(mobile apps)开发解决方案
查看>>
C/C++获取文件大小
查看>>
深入理解Java内存模型(五)——锁
查看>>
Chalubo僵尸网络来袭 IOT设备或将受到DDoS攻击
查看>>
如何实现百万TPS?详解JMQ4的存储设计
查看>>
这么说吧,NIO很简单,其实就是个牛逼IO
查看>>
七、【应用的主要框架】
查看>>
使用Python快速获取公众号文章定制电子书(二)
查看>>
iOS下JS与OC互相调用(七)--Cordova 基础
查看>>
Three.js 关于立方体贴图产生边缘锯齿问题
查看>>
Nacos v0.7.0:对接CMDB,实现基于标签的服务发现能力
查看>>
【开发问题记录①】关于滑动CollectionView时ContentSize变化的问题
查看>>