DNA Sorting POJ - 1007
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 114211 | Accepted: 45704 |
Description
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
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
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
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的更多相关文章
- Mathematics:DNA Sorting(POJ 1007)
DNA排序 题目大意:给定多个ACGT序列,按照字母顺序算出逆序数,按逆序数从小到大排列 这题其实很简单,我们只要用一个归并排序算逆序数,然后快排就可以了(插入排序也可以,数据量不大),但是要注意的是 ...
- [POJ 1007] DNA Sorting C++解题
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 77786 Accepted: 31201 ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- poj 1007 (nyoj 160) DNA Sorting
点击打开链接 DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 75164 Accepted: 30 ...
- [POJ] #1007# DNA Sorting : 桶排序
一. 题目 DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95052 Accepted: 382 ...
- poj 1007 DNA Sorting
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95437 Accepted: 38399 Des ...
- poj 1007 DNA sorting (qsort)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95209 Accepted: 38311 Des ...
- DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...
- 算法:POJ1007 DNA sorting
这题比较简单,重点应该在如何减少循环次数. package practice; import java.io.BufferedInputStream; import java.util.Map; im ...
随机推荐
- 依赖注入在 dotnet core 中实现与使用:2 使用 Extensions DependencyInjection
既然是依赖注入容器,必然会涉及到服务的注册,获取服务实例,管理作用域,服务注入这四个方面. 服务注册涉及如何将我们的定义的服务注册到容器中.这通常是实际开发中使用容器的第一步,而容器本身通常是由框架来 ...
- Disruptor系列(二)— disruptor使用
本文译自Dirsruptor在github上的wiki中文章:Getting Started 获取Disruptor Disruptor jar包可以从maven仓库mvnrepository获取,可 ...
- wpf 单例模式和异常处理 (原发布 csdn 2017-04-12 20:34:12)
第一次写博客,如有错误,请大家及时告知,本人立即改之. 如果您有好的想法或者建议,我随时与我联系. 如果发现代码有误导时,请与我联系,我立即改之. 好了不多说,直接贴代码. 一般的错误,使用下面三个就 ...
- 总结了11条,我对Python 装饰器的理解
对于每一个学习 Python 的同学,想必对 @ 符号一定不陌生了,正如你所知, @ 符号是装饰器的语法糖,@符号后面的函数就是我们本文的主角:装饰器. 装饰器放在一个函数开始定义的地方,它就像一顶帽 ...
- JS基础语法---函数练习part1---5个练习
练习1:求两个数字的和:获取任意的两个数字的和 function getSum(x, y) { return x + y; } console.log(getSum(10, 20)); 练习2:求1- ...
- gzip格式分析与识别
" 介绍gzip格式,识别gzip压缩的数据流量." 在协议分析过程中,经常会发现gzip压缩的数据,例如在HTTP协议中,在HTTP头中会标示,内容编码为gzip.DEFLATE ...
- Cygwin添加右键菜单
修改注册表 统一的方式,添加一个右键命令 找到HKEY_CLASSES_ROOT\Directory\Background\shell 右键,新建项.名字随便起 再次右键,新建项.命名command ...
- andriod8.1.0源码编译中的一个坑-package com.sun.javadoc does not exist
这里记录编译过程中的一个坑!!! 编译过程中出现了下面的报错 external/doclava/src/com/google/doclava/ClassInfo.java:20: error: pac ...
- Android O的通知渠道适配
在 Android O 以后,Google引入了通知通道的概念,如果目标API大于 Android O ,不直指定通知渠道是不能发送通知的. 这里放一个我写好的通知方法,大家可以适当的改改再用,*当 ...
- 需求规格说明书(final)
1. 引言 1.1 编写目的 该文档是关于微信小程序自习吧的功能和性能描述,重点描述了小程序的功能需求,并作为小程序开发设计阶段的主要输入. 本文档的预期读者包括:triple兔成员,软件工程老师,用 ...