poj 1007 (nyoj 160) DNA Sorting
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 75164 | Accepted: 30115 |
Description
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.
Input
Output
Sample Input
10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT
Sample Output
CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA
把每个序列的逆序数求出来然后根据逆序数稳定排序后升序输出,注意qsort中cmp函数的使用,当a == b时返回0则不处理两个数
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<string>
using namespace std;
typedef struct NODE
{
int num;
string str;
}Node; int comp(const void* a,const void* b)
{
Node* x=(Node*)a;
Node* y=(Node*)b;
return (x->num)-(y->num);
}
int main()
{
int n, m;
Node array[101];
while(cin>>n>>m)
{
int i;
for(i = 0; i < m; i++)
{
Node node;
cin>>node.str;
int j;
int count = 0;
int len = node.str.length();
for(j = 0; j < len - 1; j++)
{
int k;
if(node.str[j] == 'A')
continue;
for(k = j + 1; k < len; k++)
{
if(node.str[j] > node.str[k])
count ++;
}
}
node.num = count;
array[i] = node;
}
qsort(array, m, sizeof(Node), comp);
for(i = 0; i < m; i++)
cout<<array[i].str<<endl; }
return 0;
}
poj 1007 (nyoj 160) 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
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95437 Accepted: 38399 Des ...
- DNA Sorting POJ - 1007
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 114211 Accepted: 45704 De ...
- poj 1007 DNA sorting (qsort)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95209 Accepted: 38311 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 ...
- 算法:POJ1007 DNA sorting
这题比较简单,重点应该在如何减少循环次数. package practice; import java.io.BufferedInputStream; import java.util.Map; im ...
- [POJ1007]DNA Sorting
[POJ1007]DNA Sorting 试题描述 One measure of ``unsortedness'' in a sequence is the number of pairs of en ...
随机推荐
- react-redux知识点
1.定义组件: 2.定义action: 3.定义Reducer:reducer1(state,action): 4.定义store:store(reducer1): 5.定义mapStateToPro ...
- mysql导出查询结果到csv方法
要将MySQL的查询结果导出为csv,一般会使用php连接mysql执行查询,将返回的查询结果使用php生成csv格式再导出. 但这样比较麻烦,需要服务器安装php才可以实现. 直接使用mysql导出 ...
- 微信 JSSDK .NET版
/*因为官方 微信 JSSDK 只有PHP java版本的 我自己照着PHP的翻译过来的,可供参考.欢迎指正*/ [csharp] view plaincopy在CODE上查看代码片派生到我的代码片 ...
- C# 如何通过拼接XML调用存储过程来优化系统性能
平常新增多条记录,需要多次访问数据库,这样会影响性能:如果把新增的数据拼接成XML形式,作为参数传给存储过程来处理,这只访问数据库一次,执行速度会快很多. 1.C#代码如下:XML拼接的字段不能出现& ...
- BI案例:KPI在商业智能中的应用(ZT)
KPI(Key Performance Indication)即关键业绩指标,是通过对组织内部某一流程的输入端.输出端的关键参数进行设置.取样.计算.分析,衡量流程绩效的一种目标式量化管理指标,是把企 ...
- Spring入门学习(一)
SpringMVC基础平台补充(2016.03.03) 如果想要开发SpringMVC,那么前期依次安装好:JDK(jdk-8u74-windows-x64,安装后配置环境变量JAVA_HOME和CL ...
- [转].net 使用NPOI或MyXls把DataTable导出到Excel
本文转自:http://www.cnblogs.com/yongfa365/archive/2010/05/10/NPOI-MyXls-DataTable-To-Excel-From-Excel.ht ...
- sql数据库带补全终端命令
mysql pip install mycli pgsql pip install pgcli 都是python脚本,记录备忘.
- 【原】sql 将某列拼成一个字符串
SQL Server中,写存储过程,时常会碰到这样一个需求:从某个表中取某一列,然后需要将这一列数据以某种形式拼成一个字符串,以供后面使用,下面这种方法能够实现此需求. --取说明书模块枚举,结果格式 ...
- 黄聪:wordpress伪静态的原理
首先起作用的是配置文件的.htaccess 中的 RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [L]RewriteCond %{RE ...