POJ1007 DNA Sorting中英对照翻译与参考解答
POJ1007 DNA Sorting
传送门:POJ 1007
关键词: 水题、排序
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).
一个序列“未排序”的一个衡量标准是该字符串中次序相反的字符对的数目。例如,字母序列“DAABEC”的逆序数是5,因为D比它右边的4个字母大,而E比它右边的1个字母大。这种度量方式被称为序列中的逆序数。序列“AACEDGG”只有1个逆序(E和D)——它已经接近有序——相反,序列“ZWQM”有6个逆序(它是未排序的——完全是反向的排序)。
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.
你要对DNA字符串序列进行分类(序列仅包含4个字母A,C,G和T)。然而,分类不是按字母顺序,而是按“排序”的次序,从“最多已排序”到“最少已排序”进行排列。所有的字符串长度相同。
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.
第一行包含两个整数:一个正整数n(0 < n <= 50)给出字符串的长度,和一个正整数m(0 < m <= 100)给出字符串的数目。接下来的m行,每行为包含长度为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
East Central North America 1998
解析
- “最多已排序”的串指的是逆序数最小的串;相反,逆序数最多的串就是“最少已排序”。
- 题目的数据量不大,对逆序数的统计用冒泡排序就行了。(也可以使用分治法、树状数组来统计)
- 以逆序数为关键字排序,最终输出即可。
参考代码
#include <iostream>
#include <string>
#include <algorithm>using namespace std;
// 使用C++STL中的string,不需要规定n
const int kMaxM = 101;int n, m;typedef struct DNAInfo_ {string s; // DNA串int x; // 逆序数
} DNAInfo;DNAInfo a[kMaxM];void Swap(char& a, char& b) {char temp = a;a = b;b = temp;
}// 返回逆序数
int Stat(string s) {int count = 0;int len = s.length();// 冒泡排序for (int i = 0; i < len - 1; i++) {for (int j = 0; j < len - 1 - i; j++) {if (s[j] > s[j + 1]) {Swap(s[j], s[j + 1]);++count;}}}return count;
}bool cmp(const DNAInfo& a, const DNAInfo& b) {return a.x < b.x;
}int main() {cin >> n >> m;for (int i = 0; i < m; i++) {cin >> a[i].s;a[i].x = Stat(a[i].s);}sort(a, a + m, cmp);for (int i = 0; i < m; i++) {cout << a[i].s << endl;}return 0;
}
POJ1007 DNA Sorting中英对照翻译与参考解答相关推荐
- 论文中英对照翻译--(Fusing Multiple Deep Features for Face Anti-spoofing)
[开始时间]2018.10.22 [完成时间]2018.10.22 [论文翻译]论文中英对照翻译--(Fusing Multiple Deep Features for Face Anti-spoof ...
- 【论文翻译】GoogleNet网络论文中英对照翻译--(Going deeper with convolutions)
[开始时间]2018.09.25 [完成时间]2018.09.26 [论文翻译]GoogleNet网络论文中英对照翻译--(Going deeper with convolutions) [中文译名] ...
- 【论文翻译】中英对照翻译--(Attentive Generative Adversarial Network for Raindrop Removal from A Single Image)
[开始时间]2018.10.08 [完成时间]2018.10.09 [论文翻译]Attentive GAN论文中英对照翻译--(Attentive Generative Adversarial Net ...
- 【论文翻译】VGG网络论文中英对照翻译--(very deep convolutional networks for large-scale image recognition)
[开始时间]2018.09.23 [完成时间]2018.09.24 [论文翻译]VGG网络论文中英对照翻译--(very deep convolutional networks for large-s ...
- seq2seq (中英对照翻译)Attention
基于PyTorch实现seq2seq模型来实现中文向英文的翻译. Seq2Seq模型 seq2seq模型主要由Encoder和Decoder这两部分组成,因为是序列到序列网络,之间有两个递归神经网络一 ...
- CSS中居中的完全指南(中英对照翻译)
翻译自:https://css-tricks.com/centering-css-complete-guide/ Centering things in CSS is the poster child ...
- 星际争霸人族兵种音效中英对照翻译
Terran SCV (出场00)SCV, good to go, sir. SCV可以开工了 (Err00)I can't build it, something's in the way. 我没 ...
- (FLANN论文)fast approximate nearest neighbors with automatic algorithm configuration——中英对照翻译
Fast Approximate Nearest Neighbors With Automatic Algorithm Configuration Abstract 在许多计算机视觉问题中,最耗时的部 ...
- 计算机辅助翻译术语中英对照,翻译专业术语汇编(英汉对照
Absolute Translation 绝对翻译 Abstract Translation 摘要翻译 Abusive Translation 滥译 Acceptability 可接受性 Accura ...
最新文章
- Nature综述:从土壤到临床-微生物次级代谢产物对抗生素耐受性和耐药性的影响...
- Import-Module : 未能加载指定的模块“\Neo4j-Management.psd1”
- php中的__call调用
- 5天玩转C#并行和多线程编程 —— 第五天 多线程编程大总结
- LeetCode Construct the Rectangle
- java中mongodb中dao通用_Spring配置MongoDB及 构建通用Dao
- 毕业两年的我--奋斗中的程序员
- python文件合法模式组合_以下选项中,不是Python文件二进制打开模式的合法组合是...
- Python使用K-means聚类算法进行分类案例一则
- mysql怎么切换用户_DB2迁移到Mysql
- Oracle修改expired状态,Oracle数据库用户账号处于expired状态解决方法
- 跟踪(一):跟踪常见算法和特点
- 各个电脑品牌BIOS快捷启动热键
- 数学建模-回归分析(Stata)
- 喜报!中国工商银行长春分行荣获吉林省“巾帼建功”先进集体称号
- WPF 仿微信聊天气泡
- LruCache缓存方法
- 电脑主板资料库 10 【转至www.ongood.com.tw】【FreeXploiT收集整理】
- OpenglES2.0 for Android:来做个地球吧
- 练习牛客网笔试题--前端js--60-双色球机选一注