1379 DNA Sorting
来源:互联网 发布:阿里云ddns客户端 编辑:程序博客网 时间:2024/05/01 09:04
DNA Sorting
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2188 Accepted Submission(s): 1066
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.
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
110 6AACATGAAGGTTTTGGCCAATTTGGCCAAAGATCAGATTTCCCGGGGGGAATCGATGCAT
Sample Output
CCCGGGGGGAAACATGAAGGGATCAGATTTATCGATGCATTTTTGGCCAATTTGGCCAAA
题意:
输入几组字符串,统一长度已经给出,数量也已知,将这些字符串按自己的逆序数(不知道逆序数?那就百度吧...)从大到小输出........
刚开始没看明白题很久没做出来,后来才发现,这么简单的题.......
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct str//这里用结构体挺方便的{ char x[105]; int y;}s[105];int cmp(str a,str b)//结构体排序函数{ return a.y>b.y;}int main(){ int t,i,j,k,len,n; scanf("%d",&t); while(t--) { memset(s,0,sizeof(s)); scanf("%d%d",&len,&n); getchar();//注意 for(i=0;i<n;++i) { scanf("%s",s[i].x);//输入字符串 for(j=0;j<len;++j)//这个双循环直接就开始计算逆序数的值 { for(k=j+1;k<len;++k) { if(s[i].x[k]>=s[i].x[j])//遇到满足后面小于等于前面的,就加 1 ; { ++s[i].y; } } } } sort(s,s+n,cmp);//排序 for(i=0;i<n;++i)//输出 { printf("%s\n",s[i].x); } } return 0;}
0 0
- Hdoj 1379 DNA Sorting
- hdoj 1379 DNA Sorting
- HDU 1379 DNA sorting
- hdu 1379 DNA Sorting
- 1379 DNA Sorting
- HDU 1379:DNA Sorting
- hdu-1379 DNA Sorting
- hdu 1379 DNA Sorting
- 杭电 1379 DNA Sorting
- hdoj 1379 DNA Sorting【排序】
- DNA Sorting 1379 (字符串排序)
- 杭电1379DNA Sorting
- DNA Sorting
- DNA Sorting
- DNA Sorting
- DNA Sorting
- DNA Sorting
- DNA Sorting
- Visual Studio 各版本下载
- 典型大数题(解体模板)
- 解决AngularJS在安卓WebView中跳转时不刷新的问题
- 学习solr不错的系列博文
- java多线程学习笔记——相关名词介绍
- 1379 DNA Sorting
- JSP之JavaBean
- Android开发教程精粹30篇
- 关于指针的++
- Trie树词频统计实例
- UVALive 3971 Assemble(模拟 + 二分)
- RedHat7将网卡名称eno16777736改为eth0
- 自动生成 JsonFormat! 文档都在scaladoc里。
- view 添加边框和阴影效果