HDU 1379:DNA Sorting
DNA Sorting
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2329 Accepted Submission(s): 1145
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.
1 10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT
CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include<string.h>
#include<math.h>
using namespace std;
struct DNA
{
char c[55];
int data;
} d[105];
int nixu(char *c)
{
int k=0;
int n=strlen(c);
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)
if(c[i]>c[j])k++;
}
return k;
}
void paixu(int m)
{
for(int i=0; i<m; i++)
for(int j=0; j<m-i-1; j++)
if(d[j+1].data<d[j].data)
{
DNA a=d[j+1];
d[j+1]=d[j];
d[j]=a;
}
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
getchar();
for(int i=0; i<m; i++)
{
scanf("%s",d[i].c);
d[i].data=nixu(d[i].c);
}
paixu(m);
for(int i=0; i<m; i++)
puts(d[i].c);
}
return 0;
}
HDU 1379:DNA Sorting的更多相关文章
- 算法:POJ1007 DNA sorting
这题比较简单,重点应该在如何减少循环次数. package practice; import java.io.BufferedInputStream; import java.util.Map; im ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- [POJ1007]DNA Sorting
[POJ1007]DNA Sorting 试题描述 One measure of ``unsortedness'' in a sequence is the number of pairs of en ...
- DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...
- poj 1007 (nyoj 160) DNA Sorting
点击打开链接 DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 75164 Accepted: 30 ...
- [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(排序)
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) DNA Sorting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- HDU 1560 DNA sequence(DNA序列)
HDU 1560 DNA sequence(DNA序列) Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K ...
随机推荐
- 笔试算法题(04):实现 string & memcpy & strcpy & strlen
出题:请实现给定String的类定义: 分析:注意检查标准类构造注意事项: 解题: #include <stdio.h> #include <string.h> /** * 检 ...
- Tomcat8.0 JDK1.8 的详细配置 Win10
官网下载 先安装JDK以及JRE 之后安装Tomcat jdk配置环境变量: 用户变量:path:C:\Program Files\Java\jdk1.8.0_161\bin ( jdk安装的 ...
- 高阶函数 map,reduce, filter的用法
1. map 用法 def fun_C(x): """求平方""" return x ** 2 result = map(fun_C, my ...
- 在移动端H5开发中(关于安卓端position:fixed和position:absolute;和虚拟键盘冲突的问题,以及解决方案)
一.在开发移动端webapp时,我们经常会遇到这样的问题,当我们需要在页面底部固定一个logo或者说明时,往往会采用position:fixed进行固定定位或者absolute定位到最底部 这是一个很 ...
- <input type="button" /> 和<input type="submit" /> 的区别
<input type="button" /> 这就是一个按钮.如果你不写javascript 的话,按下去什么也不会发生.<input type="s ...
- chrome webstore
chrome webstore https://chrome.google.com/webstore/detail/set-character-encoding/bpojelgakakmcfmjfil ...
- [luoguP1022] 计算器的改良(模拟)
传送门 超级大模拟.. 代码 #include <cstdio> #include <cstring> #include <iostream> #define is ...
- Network(poj 3694)
题意:一个无向图可以有重边,下面q个操作,每次在两个点间连接一条有向边,每次连接后整个无向图还剩下多少桥(注意是要考虑之前连了的边,每次回答是在上一次的基础之上) /* tarjan+LCA 先用ta ...
- POJ 2104 K-th Number (可持久化线段树)
题目大意 给一个长度为n的序列,有m个询问,每次询问一个区间里面第k小的数. 解题分析 静态的区间第k大.复习了一下可持久化线段树. 首先对数值离散化,建一颗权值线段树.按照序列的顺序依次插入,每一个 ...
- win10笔记本相机打开黑屏无法打开笔记本相机
打开注册表编辑器(WINDOWS图标+R,或者右击左下角微软图标选择“运行(R)”),在出现的窗口输入regedit并回车(Enter)确定 进入HKEY_LOCAL_MACHINE \ SOFT ...