hdoj1379DNA Sorting
来源:互联网 发布:dota2 mac怎么全屏 编辑:程序博客网 时间:2024/06/10 00:12
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<algorithm>#include<iostream>#include<string.h>using namespace std;struct stu{char a[100];int b;}st[100];bool cmp(stu x ,stu y){if(x.b!=y.b)return x.b<y.b;elsereturn strcmp(x.a,y.a)<0;}int main(){int n;scanf("%d",&n);while(n--){int q,w,i,j,k,sum=0;scanf("%d%d",&q,&w);for(i=1;i<=w;i++){scanf("%s",st[i].a);}for(i=1;i<=w;i++){for(j=0;j<q;j++){for(k=0;k<=j;k++){if(st[i].a[j]<st[i].a[k])st[i].b++;}}}sort(st+1,st+w+1,cmp);for(i=1;i<=w;i++){printf("%s\n",st[i].a);}}return 0;}思路:用sort快排和结构体解答。这道题做的时候不会将结构体中的两个变量捆绑起来一起变化,所以请教师傅来着,虽然现在还是有点不太明白,但是会用了。
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
0 0
- hdoj1379DNA Sorting
- Sorting
- Sorting:
- Sorting
- Sorting
- Sorting
- Sorting
- Sorting
- GridView sorting
- java sorting
- java sorting
- insert-sorting
- DNA Sorting
- DNA Sorting
- Sorting Algorithms
- DNA Sorting
- DNA Sorting
- DNA Sorting
- 欢迎使用CSDN-markdown编辑器
- Spring4+Quartz2计划任务集群
- grant create synonym to SCOTT
- 在阿里云ubuntu 14.04 上部署Gogs
- 汉洛塔递归实现的思考(C语言)
- hdoj1379DNA Sorting
- VC单文件连接MYSQL示例,丢掉libmysql.dll.
- java中Date与String的相互转化
- 各种代数结构(抽象代数)总结,仿射空间和点的数学定义
- C++ 折半插入排序算法
- Reverse Integer
- utf-8转GB2312
- Android5.0新组件TabLayout+ViewPager实现Tab页面
- BZOJ3262: 陌上花开 CDQ