[POJ1007]DNA Sorting
[POJ1007]DNA Sorting
试题描述
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.
输入
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.
输出
输入示例
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT
输出示例
CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA
数据规模及约定
见“输入”
题解?
做这题练英语玩玩。并不知道这题跟 DNA 有毛关系。。。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {
if(Head == Tail) {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
return *Head++;
}
int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 110
#define maxl 60
int n, l;
char S[maxn][maxl]; vector <int> id[maxn*maxn];
void process(int x) {
int A = 0, C = 0, G = 0, sum = 0;
for(int i = l; i >= 1; i--) {
if(S[x][i] == 'A') A++;
if(S[x][i] == 'C') sum += A, C++;
if(S[x][i] == 'G') sum += A + C, G++;
if(S[x][i] == 'T') sum += A + C + G;
}
id[sum].push_back(x);
return ;
} int main() {
l = read(); n = read();
for(int i = 1; i <= n; i++) scanf("%s", S[i] + 1), process(i); for(int i = 0; i <= l * l; i++)
for(int j = 0; j < id[i].size(); j++) printf("%s\n", S[id[i][j]] + 1); return 0;
}
[POJ1007]DNA Sorting的更多相关文章
- 算法:POJ1007 DNA sorting
这题比较简单,重点应该在如何减少循环次数. package practice; import java.io.BufferedInputStream; import java.util.Map; im ...
- poj1007——DNA Sorting
Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are ...
- DNA Sorting POJ - 1007
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 114211 Accepted: 45704 De ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 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 ...
- 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 ...
- DNA Sorting(排序)
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) DNA Sorting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
随机推荐
- js中的this中使用
请先查看:http://www.jb51.net/article/41656.htm 情况一:纯粹的函数调用 这是函数的最通常用法,属于全局性调用,因此this就代表全局对象Global. 情况二:作 ...
- AngularJS开发指南13:AngularJS的过滤器详解
AngularJS过滤器是用来格式化输出数据的.除了格式化数据,过滤器还能修改DOM.这使得过滤器通常用来做些如“适时的给输出加入CSS样式”等工作. 比如,你可能有些数据在输出之前需要根据进行本地化 ...
- 使用Git进行代码管理
Git简介 Git 是 Linux Torvalds 为了帮助管理 Linux® 内核开发而开发的一个开放源码的版本控制软件. 先讲一下如何把开源项目fork到自己的github中 1. 点击图中的 ...
- css学习归纳总结
来源于:trigkit4 css学习归纳总结(一) 选择器的分组 CSS选择器分为 1.群组选择器 如:p, body, img, div{} 2.兄弟选择器 如:p + p { color:#f00 ...
- 全局唯一标识符(GUID)
全局唯一标识符,简称GUID(发音为/ˈɡuːɪd/或/ˈɡwɪd/),是一种由算法生成的唯一标识,通常表示成32个16进制数字(0-9,A-F)组成的字符串,如:{21EC2020-3AEA-106 ...
- 详解HTML中的window对象和document对象
Window -- 代表浏览器中一个打开的窗口: 对象属性 window //窗口自身 window.self //引用本窗户window=window.self window.name //为窗口命 ...
- Windows下python的配置
Windows下python的配置 希望这是最后一次写关于python的配置博客了,已经被python的安装烦的不行了.一开始我希望安装python.手动配置pip并使用pip安装numpy,然而发现 ...
- opencv笔记4:模板运算和常见滤波操作
time:2015年10月04日 星期日 00时00分27秒 # opencv笔记4:模板运算和常见滤波操作 这一篇主要是学习模板运算,了解各种模板运算的运算过程和分类,理论方面主要参考<图像工 ...
- POJ1067 取石子游戏
Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...
- 2014ACMICPC西安网赛1006
题意:给你一个骰子的初始状态和可以进行的四种操作,求从初始状态到目标状态的最少操作次数 题目本身很简单,bfs即可.但是因为骰子有六个面,搜索判重和记录状态比较麻烦.这时候就需要神器STL了. #in ...