POJ1007-DNA Sorting-ACM
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 83442 | Accepted: 33584 |
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
followed by m lines, each containing a string of length n.
Output
Sample Input
10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT
Sample Output
CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA
重点,归并排序求逆序数
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define MAXN 256
char a[MAXN];
char c[MAXN];
int cnt=;
void MergeSort(int l, int r){
int mid, i, j, tmp;
if( r > l+ ){
mid = (l+r)/;
MergeSort(l, mid);
MergeSort(mid, r);
tmp = l;
for( i=l, j=mid; i < mid && j < r; ){
if( a[i] > a[j] ){
c[tmp++] = a[j++];
cnt += mid-i; //
}
else c[tmp++] = a[i++];
}
if( j < r ) for( ; j < r; ++j ) c[tmp++] = a[j];
else for( ; i < mid; ++i ) c[tmp++] = a[i];
for ( i=l; i < r; ++i ) a[i] = c[i];
}
}
int main(void){
int n,m;
scanf("%d%d",&n,&m);
char ** strs = (char **)malloc(m*sizeof(char*));
int * cnts = (int *)malloc(m*sizeof(int));
int i;
for(i = ;i<m;i++){
strs[i] = (char *)malloc((n+)*sizeof(char));
scanf("%s",strs[i]);
//printf("%s\n",strs[i]);
cnt = ;
strcpy(a,strs[i]);
//printf("%s\n",a);
MergeSort(,n);
//printf("%d\n",cnt);
cnts[i] = cnt;
} for(i = ;i<m-;i++){
int j,p=i;
for(j = i+;j<m;j++){
if(cnts[p]>cnts[j]){
p = j;
}
}
if(p!=i){
int tmp = cnts[p];
cnts[p] = cnts[i];
cnts[i] = tmp;
char * str = strs[p];
strs[p] = strs[i];
strs[i] = str;
}
}
for(i = ;i<m;i++){
printf("%s\n",strs[i]);
free(strs[i]);
}
free(strs);
free(cnts);
return ;
}
POJ1007-DNA Sorting-ACM的更多相关文章
- [POJ1007]DNA Sorting
[POJ1007]DNA Sorting 试题描述 One measure of ``unsortedness'' in a sequence is the number of pairs of en ...
- 算法: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: ...
随机推荐
- ERROR: The node /hbase is not in ZooKeeper. It should have been written by the master. Check the value configured in 'zookeeper.znode.parent'. There could be a mismatch with the one configured in the
hbase shell下list命令出错. [hadoop@djt002 hbase]$ hbase shell 2016-07-20 19:37:12,522 INFO [main] Confi ...
- Border - SGU 133(排序)
题目大意:有N对区间现在剔除一些区间,这些区间被另一些区间完全包含,如,Ai<Bi, Bj<Aj, A完全包含B,求出来这样被包含的区间个数. 分析:首先按照第一个数字先进行一下排序,然后 ...
- GWT(Google Web Tookit) Eclipse Plugin的zip下载地址(同时提供GWT Designer下载地址)
按照Eclipse Help->Install new software->....(这里是官方安装文档:http://code.google.com/intl/zh-CN/eclipse ...
- 浅谈UML中类之间的五种关系及其在代码中的表现形式
本文转载:http://www.cnblogs.com/DebugLZQ/archive/2013/05/13/3066715.html 什么是类? 将某类东西归纳在一起,可以成为一个类. 类有很多种 ...
- 读TIJ -1 对象入门
<Thinking In Java·第 1 章对象入门> 第 1 章约20页,是对面向对象的程序设计(OOP)的一个综述. 依照其前言所述: "当中包含对"什么是对象& ...
- CoreText 实现图文混排
CoreText 实现图文混排 相关博文推荐 IOS CoreText.framework - 基本用法 IOS CoreText.framework - 段落样子CTParagraphStyle h ...
- css培训(三)
优先级 z-index 不设置 或auto 非static z-index :0 : z-index:-1: opacity 与层叠上下 opacity:.9 对其影响 小于1值 不具备堆叠 ...
- linux下杀死进程(kill)的N种方法 【转】
转自 http://blog.csdn.net/andy572633/article/details/7211546 首先,用ps查看进程,方法如下: $ ps -ef ……smx 182 ...
- js兼容各个浏览器的复制功能
看似简单的复制功能,用js做起来竟然遇到各种情况.刚开始在网上搜索到复制功能的几种实现方法,但是都不兼容.最后还是用的插件代码如下 html模板 <tr> <td>1</ ...
- Html网页生成Pdf
在http://code.google.com/p/wkhtmltopdf/downloads/list下载安装程序. 1.添加引用 using System.Diagnostics; 添加引用 2. ...