DNA Sorting
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 114211   Accepted: 45704

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 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT

Sample Output

CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA

Source

OJ-ID:
poj-1007

author:
Caution_X

date of submission:
20191010

tags:
水题

description modelling:
1.输入若干个字符串,按“有序”到“无序”顺序输出(这些串只含有A,C,G,T)
2.有序的定义为该串的逆序数,若逆序数相同,则按原来的顺序输出

major steps to solve it:
1.记录所在串各个字母的个数
2.遍历整个串,每次遍历到当前字母时加上与该字母逆序的字母的个数,然后该串中此字母个数-1
3.sort排序后输出
warnings:
1.注意审题,逆序数相同时按照原来的顺序输出
AC Code:

#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
char a[][];
map<char,int> Num[];
struct ANS{
int d,p;
}ans[];
int d[];
bool cmp(ANS a,ANS b)
{
if(a.d!=b.d) return a.d<b.d;
else return a.p<b.p;
}
int main()
{
//freopen("input.txt","r",stdin);
int n,m;
cin>>n>>m;
for(int i=;i<m;i++) {
ans[i].p=i;
for(int j=;j<n;j++) {
cin>>a[i][j];
Num[i][a[i][j]]++;
}
}
for(int i=;i<m;i++) {
ans[i].d=;
for(int j=;j<n;j++) {
if(a[i][j]=='A') {
Num[i]['A']--;
}
else if(a[i][j]=='C') {
ans[i].d=ans[i].d+Num[i]['A'];
Num[i]['C']--;
}
else if(a[i][j]=='G') {
ans[i].d=ans[i].d+Num[i]['A']+Num[i]['C'];
Num[i]['G']--;
}
else if(a[i][j]=='T') {
ans[i].d=ans[i].d+Num[i]['C']+Num[i]['G']+Num[i]['A'];
Num[i]['T']--;
}
}
}
sort(ans,ans+m,cmp);
for(int i=;i<m;i++) {
for(int j=;j<n;j++) {
cout<<a[ans[i].p][j];
}
cout<<endl;
}
return ;
}

DNA Sorting POJ - 1007的更多相关文章

  1. Mathematics:DNA Sorting(POJ 1007)

    DNA排序 题目大意:给定多个ACGT序列,按照字母顺序算出逆序数,按逆序数从小到大排列 这题其实很简单,我们只要用一个归并排序算逆序数,然后快排就可以了(插入排序也可以,数据量不大),但是要注意的是 ...

  2. [POJ 1007] DNA Sorting C++解题

        DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 77786   Accepted: 31201 ...

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

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

  4. poj 1007 (nyoj 160) DNA Sorting

    点击打开链接 DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 75164   Accepted: 30 ...

  5. [POJ] #1007# DNA Sorting : 桶排序

    一. 题目 DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95052   Accepted: 382 ...

  6. poj 1007 DNA Sorting

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95437   Accepted: 38399 Des ...

  7. poj 1007 DNA sorting (qsort)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95209   Accepted: 38311 Des ...

  8. DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏

    DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...

  9. 算法:POJ1007 DNA sorting

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

随机推荐

  1. Installation request for topthink/think-captcha ^3.0 -> satisfiable by topthink/think-captcha[v3.0.0].

    ThinkPHP5.1安装图形验证码的时候报错: Problem 1 - Installation request for topthink/think-captcha ^3.0 -> sati ...

  2. NGINX 配置清单

    以下内容来自 SimulatedGREG/nginx-cheatsheet. 通用设置 端口 listen server { # standard HTTP protocol listen 80; # ...

  3. vue-列表动画

    实现列表动画 li { border: 1px dashed #999; margin: 5px; line-height: 35px; padding-left: 5px; font-size: 1 ...

  4. 阿里P7工作总结:Spring MVC的工作原理,看完受益匪浅

    这篇文章将深入探讨Spring框架的一部分——Spring Web MVC的强大功能及其内部工作原理. 项目安装 在本文中,我们将使用最新.最好的Spring Framework 5.我们将重点介绍S ...

  5. vue 地图可视化 maptalks 篇

    Maptalks 项目是一个 HTML5 的地图引擎, 基于原生 ES6 Javascript 开发: - 二三维一体化地图, 通过二维地图的旋转 /倾斜增加三维视角 - 插件化设计, 能与其他图形库 ...

  6. xcode 运行出现的相应配置问题以及解决办法

    在学习iOS开发的过程中,经常会在网上找一些demo学习,但是网上找的demo,在自己的机子上都会出各种各样的问题.下面我来整理一下,我所遇到的问题. 最近在接受一个比较老的混合开发的项目,出现了一下 ...

  7. 剑指offer 16:反转链表

    题目描述 输入一个链表,反转链表后,输出新链表的表头. 解题思路 单链表原地反转是面试手撕代码环节非常经典的一个问题.针对一般单链表,反转的时候需要操作的是当前节点及与之相邻的其他两个节点.因而需要定 ...

  8. dart lang 开发环境

    ========================Dart SDK 下载========================Dart SDK 主页: https://dart.dev/toolsDart S ...

  9. git零基础快速入门实战,重点讲解,在实际生产中整合idea对版本、分支的管理等

    1.什么是版本管理 (多人协作)项目中常见的问题: 代码放在什么地方 ?? 同步(到服务器),代码的冲突问题 ?? 服务器访问权限问题 ?? (代码)服务器内容修改的细节 ?? 项目版本的发布 ?? ...

  10. 借助meta影藏顶部菜单

    1===>报错 Cannot find module 'webpack/lib/Chunk' 删除node_modules 然后重新下载 4==> 现在已进入页面,底部就有四个菜单,在点击 ...