poj 1007 DNA Sorting
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 95437 | Accepted: 38399 |
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
Output
Sample Input
10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT
Sample Output
CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA 题目大意:根据字符串的逆序数,从小到大输出字符串。
思路:将字符串和它的逆序数联系起来,通过对它的逆序数从小到大排序,对字符串排序。。。用结构体解决,用sort函数排序。
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; typedef struct{
char s[];
int num;
}DNA; //求一个字符串的逆序数
int InversionNumber(char *s, int n){
int num = ;
for(int i = ; i < n - ; i++)
for(int j = i + ; j < n; j++){
if(s[i] > s[j])
num++;
}
return num;
} bool cmp(DNA a, DNA b){
return a.num < b.num;
} int main(){
int n, m;
cin >> n >> m;
DNA *a = new DNA [m];
for(int i = ; i < m; i++){
cin >> a[i].s;
a[i].num = InversionNumber(a[i].s, n);
}
sort(a, a + m, cmp); for(int i = ; i < m; i++)
cout << a[i].s << endl;
return ;
}
poj 1007 DNA Sorting的更多相关文章
- [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# DNA Sorting : 桶排序
一. 题目 DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95052 Accepted: 382 ...
- poj 1007 DNA sorting (qsort)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95209 Accepted: 38311 Des ...
- poj 1007 DNA Sorting 解题报告
题目链接:http://poj.org/problem?id=1007 本题属于字符串排序问题.思路很简单,把每行的字符串和该行字符串统计出的字母逆序的总和看成一个结构体.最后把全部行按照这个总和从小 ...
- POJ 1007 DNA Sorting(sort函数的使用)
Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are ...
- POJ 1007 DNA sorting (关于字符串和排序的水题)
#include<iostream>//写字符串的题目可以用这种方式:str[i][j] &str[i] using namespace std; int main() {int ...
- poj 107 DNA sorting
关于Java的题解,也许效率低下,但是能解决不只是ACGT的序列字符串 代码如下: import java.util.*; public class Main { public static void ...
- poj 1007 (nyoj 160) DNA Sorting
点击打开链接 DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 75164 Accepted: 30 ...
随机推荐
- bzoj1143 2718
最小可相交路径覆盖 先预处理可到达的点然后转化为最小不相交路径覆盖 type node=record point,next:longint; end; ..] of node; ...
- BZOJ_1778_[Usaco2010_Hol]_Dotp_驱逐猪猡_(期望动态规划+高斯消元+矩阵)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1778 炸弹从1出发,有\(\frac{P}{Q}\)的概率爆炸,如果不爆炸,等概率移动到连通的 ...
- Dell笔记本禁用触摸板的方法
一·找到触摸板驱动所在的文件夹(其他型号 的本本,请自己探索一下,找到驱动在哪就行),一般 在 C:\program files\delltpad 中(若没有请下载安 装 ),如图: 二·双击 Del ...
- MyEclipse常用操作技巧
1.源码和帮助文档的的关连 下面以关联struts2-core-2.3.14.2.jar源代码为例: 如下为示意图 2.拷贝项目的时候,要注意 将项目的web-root fold改成更新后的名字项目名 ...
- word 中Sentences、Paragraph等含义和用法
word 中有Words,Characters,Sentences.Paragraph,Sections 具体含义如下表达式 含义 返回的对象 Words(index) ...
- Data binding 在Activity,Fragment中引用以及加载其他布局
Data binding在Activity中使用: DataBindingUtil.setContentView(this, R.layout.activity_home); Data binding ...
- 【JS】Beginner3 & 4 & 5 & 6:Maths & Logic & Conditonal & Looping
1.number operator () * / + - 2.logic make decisions in code compare values to produce a boolean valu ...
- Java笔记(十二)……类中各部分加载顺序及存放位置问题
什么时候会加载类 使用到类中的内容时加载,三种情况: 创建对象:new StaticDemo(); 使用类中的静态成员:StaticCode.num = 9; StaticCode.getNum() ...
- oracle 高水位线
一.oracle 高水位线详解 一.什么是水线(High Water Mark)? 概念: 1.块: 是粒度最小的存储单位,现在标准的块大小是8K,ORACLE每一次I/O操作也是按块来操作的,也就是 ...
- .NET版本问题 转[.Net Framework Initialization Error – Unable to find a version of the runtime to run this applicatio]
转自:http://blog.csdn.net/rrrrssss00/article/details/7069009 dev注册程序问题部署一个VS2010开发的程序时遇到 了一个非常奇怪的问题,客户 ...