DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏
DNA Sorting
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 88690 Accepted: 35644
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 sequenceDAABEC”, 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 sequenceZWQM” 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'', frommost sorted” to “least sorted”. All the strings are of the same length.
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.
Output
Output the list of input strings, arranged from most sorted'' toleast 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
大致的意思就是对DNA的逆序数排序
#include <iostream>
#include <string>
#include <algorithm>
#define RR freopen("input.txt","r",stdin)
#define WW freopen("ouput.txt","w",stdout)
using namespace std;
const int INF=0x3f3f3f3f;
int n,m;
struct DNA
{
string str;
int num ;
void NUM()
{
num=0;
for(int i=0;i<n;i++)
{
int sum=0;
for(int j=i-1;j>=0;j--)
{
if(str[i]<str[j])
{
sum++;
}
}
num+=sum;
}
}
}D[110];
bool cmp(DNA a,DNA b)
{
return a.num<b.num;
}
int main()
{
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>D[i].str;
D[i].NUM();
}
sort(D,D+m,cmp);
for(int i=0;i<m;i++)
{
cout<<D[i].str<<endl;
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏的更多相关文章
- hadoop调优之一:概述 分类: A1_HADOOP B3_LINUX 2015-03-13 20:51 395人阅读 评论(0) 收藏
hadoop集群性能低下的常见原因 (一)硬件环境 1.CPU/内存不足,或未充分利用 2.网络原因 3.磁盘原因 (二)map任务原因 1.输入文件中小文件过多,导致多次启动和停止JVM进程.可以设 ...
- 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...
- Poj 2559 最大矩形面积 v单调栈 分类: Brush Mode 2014-11-13 20:48 81人阅读 评论(0) 收藏
#include<iostream> #include<stack> #include<stdio.h> using namespace std; struct n ...
- Dijkstra with priority queue 分类: ACM TYPE 2015-07-23 20:12 4人阅读 评论(0) 收藏
POJ 1511 Invitation Cards(单源最短路,优先队列优化的Dijkstra) //================================================= ...
- NYOJ 119 士兵杀敌(三)【ST算法】 分类: Brush Mode 2014-11-13 20:56 101人阅读 评论(0) 收藏
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=119 解题思路: RMQ算法. 不会的可以去看看我总结的RMQ算法. http://blo ...
- bzoj 1041 圆上的整点 分类: Brush Mode 2014-11-11 20:15 80人阅读 评论(0) 收藏
这里先只考虑x,y都大于0的情况 如果x^2+y^2=r^2,则(r-x)(r+x)=y*y 令d=gcd(r-x,r+x),r-x=d*u^2,r+x=d*v^2,显然有gcd(u,v)=1且u&l ...
- HTTP 错误 500.19- Internal Server Error 错误解决方法 分类: Windows服务器配置 2015-01-08 20:16 131人阅读 评论(0) 收藏
1.第一种情况如下: 解决方法如下: 经过检查发现是由于先安装Framework组件,后安装iis的缘故,只需重新注册下Framework就可以了,具体步骤如下 1 打开运行,输入cmd进入到命令提示 ...
- winform Execl数据 导入到数据库(SQL) 分类: WinForm C# 2014-05-09 20:52 191人阅读 评论(0) 收藏
首先,看一下我的窗体设计: 要插入的Excel表: 编码 名称 联系人 电话 省市 备注 100 100线 张三 12345678910 北京 测试 101 101线 张三 12345678910 上 ...
- House Robber 分类: leetcode 算法 2015-07-09 20:53 2人阅读 评论(0) 收藏
DP 对于第i个状态(房子),有两种选择:偷(rob).不偷(not rob) 递推公式为: f(i)=max⎧⎩⎨⎪⎪{f(i−1)+vali,f(i−2)+vali,robi−1==0robi−1 ...
随机推荐
- 使用Genymotion来运行Android Studio开发的程序
访问网址:https://www.genymotion.com,注册账户,之后下载,下载时需要注意不要选择(withou virtualbox那个) 之后运行安装, 运行Genymotion运行启动G ...
- Excel公式无法重算,暂无法解决
一份复杂的excel报表,某些单元格是用求和公式算出来的值,但生成之后,用excel打开,无法显示公式结果,按F9也没有用,只能在单元格公式双击后回车才会显示.而在WPS2010按F9就可以重算,WP ...
- java collections读书笔记(9)collection框架总览(2)
框架算法: 1)collection接口 add() Adds an element to the collection.addAll() Adds a collection of element ...
- PostgreSQL Replication之第十二章 与Postgres-XC一起工作(7)
12.7 处理故障转移和删除节点 在本节中,我们将看看故障切换如何处理.我们还将看看如何使用安全可靠的方法添加节点到Postgres-XC设置以及如何从Postgres-XC设置删除节点. 12.7. ...
- 汉字转【pinyin】
引言 github地址:aizuyan/pinyin 无意中看到了overtrue/pinyin这个项目,感觉很有意思,这个项目做了这么一件事情: 将汉字转化为拼音 刚看到这里是不是觉得没什么难度,没 ...
- WEB简单数据操作练习
主要学习代码: Login.aspx: <!--第一种方式--> <%-- <script type="text/javascript"> funct ...
- cocos2dx建立项目
http://www.cocos.com/doc/article/index?type=wiki&url=/doc/cocos-docs-master/manual/framework/nat ...
- clock gating and PLL
一个gating的clock是指:clock network除了包含inverter和buffer外,还有其他logic. PrimeTime会自动的对gating input进行setup和hold ...
- MySQL函数汇总
前言 MySQL提供了众多功能强大.方便易用的函数,使用这些函数,可以极大地提高用户对于数据库的管理效率,从而更加灵活地满足不同用户的需求.本文将MySQL的函数分类并汇总,以便以后用到的时候可以随时 ...
- 记一个由MemCached引发的性能问题
最近有个项目用loadrunner做了压力测试,发现并发量还不到200服务器就支撑不住了.boss那边紧急开会,说此项目最近3个月内将有100家中大型公司用于校园招聘工作,如果这个问题不解决公司有可能 ...