DNA Sorting

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2182    Accepted Submission(s): 1062

Problem 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).

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.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

 
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 (1 < m <= 100) giving the number of strings. These are followed by m lines, each containing a string of length n.
 
Output
Output the list of input strings, arranged from ``most sorted'' to ``least sorted''. If two or more strings are equally sorted, list them in the same order they are in the input file.
 
Sample Input
1 10 6 AACATGAAGG TTTTGGCCAA TTTGGCCAAA GATCAGATTT CCCGGGGGGA ATCGATGCAT
 
Sample Output
CCCGGGGGGA AACATGAAGG GATCAGATTT ATCGATGCAT TTTTGGCCAA TTTGGCCAAA
 

思路:从小到大排列。。。不好说,看题;

代码:

 #include<stdio.h>
#include<algorithm>
using namespace std;
typedef struct{
int num;
char str[];
}node;
int cmp(node a,node b){
return a.num<b.num;
}
int search(int n,char *a){int flot=;
for(int i=;i<n;++i){
for(int j=i+;j<n;++j){
if(a[j]-a[i]<)flot++;
}
}
return flot;
}
int main(){
int m,n,T;
node dna[];
scanf("%d",&T);
while(T--){scanf("%d%d",&n,&m);
int i=;
for(int i=;i<m;++i){
scanf("%s",dna[i].str);
dna[i].num=search(n,dna[i].str);
}
sort(dna,dna+m,cmp);
for(int i=;i<m;++i)printf("%s\n",dna[i].str);
}
return ;
}

快排:

#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
typedef struct{
int num;
char str[];
}node;
node dna[];
int search(int n,char *a){
int flot=;
for(int i=;i<n;++i){
for(int j=i+;j<n;++j){
if(a[j]-a[i]<)flot++;
}
}
return flot;
}
void Swap(node &a, node &b){
swap(a.num, b.num);
char s[];
strcpy(s, a.str);
strcpy(a.str, b.str);
strcpy(b.str, s);
}
int handle(int l, int r){
int j = l - ;
for(int i = l; i <= r; i++){
if(dna[i].num <= dna[r].num){
j++;
Swap(dna[i], dna[j]);
}
}
return j;
}
void quiksort(int l, int r){
int m;
if(l < r){
m = handle(l, r);
quiksort(l, m - );
quiksort(m + , r);
}
}
int main(){
int m,n,T; scanf("%d",&T);
while(T--){scanf("%d%d",&n,&m);
int i=;
for(int i=;i<m;++i){
scanf("%s",dna[i].str);
dna[i].num=search(n,dna[i].str);
}
quiksort(, m - );
for(int i=;i<m;++i)printf("%s\n",dna[i].str);
}
return ;
}

DNA Sorting(排序)的更多相关文章

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

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

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

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

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

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

  4. poj 1007 (nyoj 160) DNA Sorting

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

  5. poj 1007 DNA Sorting

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

  6. [POJ 1007] DNA Sorting C++解题

        DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 77786   Accepted: 31201 ...

  7. DNA Sorting POJ - 1007

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

  8. DNA Sorting

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 105159   Accepted: 42124 De ...

  9. 算法:POJ1007 DNA sorting

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

随机推荐

  1. XTU OJ 1209 Alice and Bob 2014(嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛)

    Problem Description The famous "Alice and Bob" are playing a game again. So now comes the ...

  2. WEB服务器6--IIS架构补充篇

    第一部分我将谈谈IIS的两个不同的版本—IIS 5.x 和 IIS 6的处理模型:IIS如何监听来自外界的Http request,如何根据ISAPI Extension Mapping将对于不同Re ...

  3. ServiceAccount 枚举

    指定服务的安全上下文,安全上下文定义其登录类型. 命名空间:  System.ServiceProcess程序集:  System.ServiceProcess(在 System.ServicePro ...

  4. border-radius讲解1

    如今CSS3中的border-radius出现后,让我们没有那么多的烦恼了,首先制作圆角图片的时间是省了,而且其还有多个优点:其一减少网站的维护的工作量,少了对图片的更新制作,代码的替换等等;其二.提 ...

  5. 配置IIS

    1.aspnet_regiis -i 重新安装IIs  vs2013的命令符 2. 分配权限 1.对文件夹,权限,安全,分配权限 2.设置webconfig 对应的httpModel 及安全性 3.设 ...

  6. Intellij Idea 配置database 连接SQL Server 2012

    首先确认通过TCP IP来连接连接SQLServer 2012     确保 Server Authentication选择了SQL Server and Windows Authentication ...

  7. 关闭显卡快捷键 CTRL+ALT+方向键

    eclipse中的CTRL+ALT+方向键  会和电脑的快捷键进行冲突,按照以下的方法就可以解决了 打开控制面板,找到“显示”(图中圈划的),点击进入        找到”更改显示器设置“,点击进入 ...

  8. oracle生成随机数

    UPDATE busi_chance_info t    SET t.exp_amount =        (SELECT floor(dbms_random.value(1, 10000000)) ...

  9. codeforces 337D Book of Evil(dp)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Book of Evil Paladin Manao caught the tra ...

  10. Java的反射机制及应用实例

    一:什么是反射机制 简单的来说,反射机制指的是程序在运行时能够获取自身的信息.在Java中,只要给定类的名字,那么就可以通过反射机制来获得类的所有信息. 二:哪里用到反射机制 我们用过一些知识,但是并 ...