[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.

输出

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.

输入示例

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的更多相关文章

  1. 算法:POJ1007 DNA sorting

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

  2. poj1007——DNA Sorting

    Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are ...

  3. DNA Sorting POJ - 1007

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

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

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

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

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

  6. poj 1007 (nyoj 160) DNA Sorting

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

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

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

  8. poj 1007 DNA Sorting

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

  9. DNA Sorting(排序)

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) DNA Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

随机推荐

  1. Bootstrap系列 -- 34. 按钮下拉菜单

    按钮下拉菜单仅从外观上看和上一节介绍的下拉菜单效果基本上是一样的.不同的是在普通的下拉菜单的基础上封装了按钮(.btn)样式效果.简单点说就是点击一个按钮,会显示隐藏的下拉菜单.按钮下拉菜单其实就是普 ...

  2. 关于#define预处理指令的一个问题

    背景:由于经常需要在远程服务端和测试服务端进行切换,所以将接口的地址定义为了一个预处理变量,例如 //#define APIDOMAIN @"http://10.0.0.2" #d ...

  3. ajax使用post提交中文

    Ajax使用POST提交中文乱码问题 前段时间写JSP,使用AJAX以POST方式提交数据,如果是中文字符提交就会乱码,后来写ASP时用到AJAX以POST方式提交数据,中文一样是乱码.搜索一下相关资 ...

  4. 过滤器-->GZIP压缩

    1.创建一个 可以使用GZIPOutputStream 压缩的流 package com.zh.yasuo2; import java.io.IOException; import java.util ...

  5. oracle-7参数文件的管理

    参数文件的管理:1.参数文件的作用:记录数据库的配置的 (1)pfile  ---> 文本文件 (2)spfile --->服务器的参数文件(二进制的) 两个参数文件的区别: pfile ...

  6. 从零开始设计SOA框架(二):请求/响应参数的设计

    每个接口都有请求参数.响应参数.其中请求参数分为公共参数和业务参数.响应参数分为两类:正常的响应参数.统一的错误参数   一.请求参数 1.公共参数:每个接口都有的参数,主要包含appkey.时间戳. ...

  7. 使用TransactionScopeOption 管理事务流

    可通过调用一个方法来嵌套事务范围,该方法在使用其自己范围的方法中使用 TransactionScope,下面示例中的 RootMethod 方法就是前者这样的方法. void RootMethod() ...

  8. Java-httpClient警告: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.

    使用HttpClient,总是报出“Going to buffer response body of large or unknown size. Using getResponseBodyAsStr ...

  9. 详解Java中ArrayList、Vector、LinkedList三者的异同点

    转载:https://my.oschina.net/zzw922cn/blog/491631 一.ArrayList ArrayList是一个可以处理变长数组的类型,这里不局限于"数&quo ...

  10. appium-车友会欢迎界面向右滑动4次点击‘立即体验’进入首屏

    代码如下: driver.swipe(610, 2452, 658, 2452, 200) 只是示例滑动1页,可以使用循环,下一页比上一页x坐标大48