DNA Sorting

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

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

这个题开始就没读懂,所以也不会做,后来学长讲完后才明白啥意思;

就是比如第一行数据AACATGAAGG     首先定义sum=0, A大于它后面字符的个数为0,sum+=0,第二个同样,第三个C大于它后面字符的个数为3,sum+=3。。。以此类推!

然后按每行数字从小到大输出字符串!!!

 #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct as
{
char s[];
int m;
}aa[];
bool cmp(as s,as t)
{
return s.m < t.m;
}
int main()
{
int n,i,j,k,t,a,b,q;
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&a,&b);
getchar();
for(k=;k<b;k++)
{ scanf("%s",aa[k].s);
{
for(t=;t<a;t++)
{
int sum=;
for(i=;i<a-;i++)
{
for(j=i+;j<a;j++)
if(aa[t].s[i]>aa[t].s[j])
sum++;
}
aa[t].m=sum;//将各组总数放在结构体中
} }
}
sort(aa, aa+b, cmp);//排序结构体
for(i=;i<b;i++)
printf("%s\n",aa[i].s);
}
return ;
}

DNA Sorting--hdu1379的更多相关文章

  1. 算法:POJ1007 DNA sorting

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

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

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

  3. [POJ1007]DNA Sorting

    [POJ1007]DNA Sorting 试题描述 One measure of ``unsortedness'' in a sequence is the number of pairs of en ...

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

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

  5. poj 1007 (nyoj 160) DNA Sorting

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

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

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

  7. poj 1007 DNA Sorting

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

  8. DNA Sorting(排序)

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) DNA Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

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

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

  10. HDU 1379:DNA Sorting

    DNA Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

随机推荐

  1. 雅思创始人Keith Taylor谈英语学习

    雅思创始人Keith Taylor谈英语学习 “要学的是信息,而不是语言” 我们要学习一个国家的语言就得知道这个国家的方方面面.要学习英语就得了解英美国家的社会.经济.人文.历史等各方面的信息. 大家 ...

  2. FileAttributes枚举

    FileAttributes枚举是一个专门用于标记硬盘上的文件属性的枚举,枚举的说明在这里:http://www.cnblogs.com/kissdodog/archive/2013/01/16/28 ...

  3. 【MVC4 之 ViewData ViewBag TempData】

    ViewData (一个字典集合类型):传入的key必须是string类型,可以保存任意对象信息,特点:它只会存在这次的HTTP的要求中而已,并不像session可以将数据带到下一个Http要求. V ...

  4. GetCurrentDirectory、SetCurrentDirectory和GetModuleFileName

    DWORD GetCurrentDirectory( DWORD nBufferLength, // size of directory buffer LPTSTR lpBuffer      // ...

  5. UIScollView Touch事件

    customScrollView.h #import <UIKit/UIKit.h> @interface customScrollView : UIScrollView @end cus ...

  6. JavaScript面向对象精要(一)

    数据类型 在JavaScript中,数据类型分为两类: 原始类型:保存一些简单数据,如true.5等.JavaScript共同拥有5中原始类型: boolean:布尔.值为true或false num ...

  7. sqlite数据库读写在linux下的权限问题

    近期在学linux,恰巧有个php项目要做.于是配置好环境打算在linux下做. 无奈站点执行后一片空白.经过调试发现是sqlite数据库的问题. 安装sqlite扩展 apt-get install ...

  8. 关于Oracle SQL/82标准和SQL/92标准

    在ORACLE9i之前,oracle语法基础是SQL/86标准,9i及之后的版本中支持SQL/92标准.基表信息:products.purchases和product_types SQL> se ...

  9. kvm虚拟化之克隆篇

    注意:在克隆虚拟机的时候,该虚拟机必须处于关闭状态. 1,查看目前有哪些子机并选择要克隆的子机,我选择关闭test,说明我要克隆的就是它了. 2,查看虚拟机是否关闭. virsh  list --al ...

  10. .Net+MySQL

    网上很少用.Net+MySQL的组合的,所以资料比较少,发现一个赶紧分享给大家. 通常数据库连接字符串为:Database=dbname;Data Source=192.168.1.1;Port=33 ...