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. ARM64 的 memcpy 优化与实现

    参考:https://www.byteisland.com/arm64-%E7%9A%84-memcpy-%E6%B1%87%E7%BC%96%E5%88%86%E6%9E%90/ libc/stri ...

  2. [转]探索ASP.NET Core 3.0 系列

    这是该系列的第一篇文章:探索ASP.NET Core 3.0. 第1部分-探索新的项目文件Program.cs和通用主机(本文) 第2部分-比较ASP.NET Core 3.0模板之间的Startup ...

  3. Redis for OPS 03:数据安全与持久化

    写在前面的话 通过前两节,除了安装部分,其它的更多的是作为了解,除非我们面向实际的开发,当然知道更多总是好的,这样才有吹牛逼的资本. 从本节开始我们主要谈谈作为一个运维,在处理 Redis 的维护的时 ...

  4. 关于WIN7下IE8IE7浏览器无法安装微信支付商户证书的解决方案

    关于WIN7下IE8IE7浏览器无法安装微信支付商户证书的解决方案 解决方案就是使用 chrome浏览器 默认的chorme浏览器  打开微信商户平台 会提示让安装控件  然后反复安装 其实要解决这个 ...

  5. 自定义Visual Studio调试器中的对象显示方式

    你有没有盯着调试器窗口中的对象,并希望你可以通过其他类型的东西来查看这些对象?我当然有!扩展项目以确定每个人的身份可能会非常快速.理想情况下,通过特定的属性值快速定位它们会很棒.对我们来说幸运的是,V ...

  6. 简单解决 VMWare “无法打开内核设备:\\Global\\vmx86”错误

    在“服务”后右击选择使用管理员打开.然后在一大串服务中找到vm开头的服务项,全部都启动.重新启动vm就ok了(vm需要以管理员身份打开).

  7. Abp vNext框架 从空项目开始 使用ASP.NET Core Web Application-笔记

    参考 Abp vNext框架 从空项目开始 使用ASP.NET Core Web Application http://www.vnfan.com/helinbin/d/745b1e040c9b4f6 ...

  8. java基础(22):File、递归

    1. File 1.1 IO概述 回想之前写过的程序,数据都是在内存中,一旦程序运行结束,这些数据都没有了,等下次再想使用这些数据,可是已经没有了.那怎么办呢?能不能把运算完的数据都保存下来,下次程序 ...

  9. Maven设置本地仓和阿里云远程仓

    在maven项目导入jar包坐标时需要连接maven官方仓库下载,但是下载速度感人,所以来修改一下设置. 设置成为本地仓和连接阿里云的远程仓库. (本地仓如果没有这个jar) 找出相应配置文件:例如我 ...

  10. Unity API学习笔记(2)-GameObject的3种Message消息方法

    官方文档>GameObject 首先建立测试对象: 在Father中添加两个脚本(GameObejctTest和Target),分别用来发送Message和接受Message: 在其它GameO ...