DNA Sorting
DNA Sorting
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 105159 | Accepted: 42124 |
Description
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.
Input
Output
Sample Input
10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT
Sample Output
CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA
题目大意:
序列“未排序程度”的一个计算方式是元素乱序的元素对个数。例如:在单词序列“DAABEC'”中,因为D大于右边四个单词,E大于C,所以计算结果为5。这种计算方法称为序列的逆序数。序列“AACEDGG”逆序数为1(E与D)——近似排序,而序列``ZWQM'' 逆序数为6(它是已排序序列的反序)。
你的任务是分类DNA字符串(只有ACGT四个字符)。但是你分类它们的方法不是字典序,而是逆序数,排序程度从好到差。所有字符串长度相同。
输入:
第一行包含两个数:一个正整数n(0<n<=50)表示字符串长度,一个正整数m(0<m<=100)表示字符串个数。接下来m行,每行一个长度为n的字符串。
输出:
输出输入字符串列表,按排序程度从好到差。如果逆序数相同,就原来顺序输出。
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef struct node{
char d[];
int value;
}DNA;
int GetValue(char *s,int len)
{
int value=;
char temp;
for(int i=;i<len-;i++)
{
temp = s[i];
for(int j=i+;j<len;j++)
{
if(temp>s[j]) value++;
}
}
return value;
}
bool MyCom(DNA a,DNA b)
{
return a.value<b.value;
}
int main()
{
int len,n;
DNA MyDNA[];
scanf("%d%d",&len,&n);
//DNA *MyDNA = new DNA[n];
for(int i=;i<n;i++)
{
scanf("%s",MyDNA[i].d);
MyDNA[i].value = GetValue(MyDNA[i].d,len);
} sort(MyDNA,MyDNA+n,MyCom); for(int i=;i<n;i++){
cout<<MyDNA[i].d<<"\0"<<endl;
}
delete []MyDNA;
return ;
}
排序部分可以用<algorithm>
里面的sort,也可以是自定义的。输入部分如果将scanf改为cin.getline(d[i].s, m+1)
则需要先用一个scanf("%c", &c)
读取两个整数之后的回车符。
sort对结构体中某一元素进行排序
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct example
{
int elem1;
int elem2;
}example;
/*这个comparison函数很重要.如果希望升序排序,就是"<",降序排列就是">"号,这样便于直观记忆.如果希望用elem2作为比较标准
就把elem1改为elem2,这样结构体就以elem2为比较标准排序了.*/
bool comparison(example a,example b){
return a.elem1<b.elem1;
}
int main()
{
int N;
fin>>N;
vector<example> array(N);
for(int i=;i<N;i++)
{
fin>>array[i].elem1>>array[i].elem2;
}
sort(array.begin(),array.end(),comparison搜索);
for(int i=;i<N;i++)
{
cout<<array[i].elem1<<" "<<array[i].elem2<<endl;
}
return ;
}
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: ...
- [POJ 1007] DNA Sorting C++解题
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 77786 Accepted: 31201 ...
- HDU 1379:DNA Sorting
DNA Sorting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
随机推荐
- 在eclipse导入项目的步骤
1. Import 2. Next 3. 确定 选中copy projects into workspace Finish 这样项目就导入进来了. 4.导入jar包 Configure Bui ...
- nodejs request module里的json参数的一个坑
今天工作的时候遇到一个坑,在客户端用nodejs给服务器发送HTTP请求,服务器老是报错:In the context of Data Services an unknown internal ser ...
- elasticsearch 数据备份
ES数据备份找了一些方法,发现elasticdump 这个工具不错 elasticdump --input=http://192.168.0.92:9200/hs2840 --output ./hs2 ...
- 十六, k8s集群资源需求和限制, 以及pod驱逐策略。
目录 容器的资源需求和资源限制 QoS Classes分类 Guaranteed Burstable Best-Effort kubernetes之node资源紧缺时pod驱逐机制 Qos Class ...
- [USACO15FEB]Superbull 超级牛
题意概况 题目描述 \(Bessie\)和她的朋友们正在一年一度的\(Superbull\)锦标赛中打球,而\(Farmer John\)负责让比赛尽可能激动人心. 总共有 \(N\) 支队伍 \(1 ...
- 寻找一组数中最大的K个数
对于"从一组数中挑出最大的K个数"这个在面试中经常会遇到,所以这次好好的去解析它,而当拿到这个问题时第一时间能想到解法就是:先对数据进行排序,然后再取最大的K个元素,当然这思路没毛 ...
- 【NOIP/CSP2019】D1T2 括号树
原题: 因为是NOIP题,所以首先先看特殊数据,前35分是一条长度不超过2000的链,N^2枚举所有子区间暴力check就能拿到分 其次可以思考特殊情况,一条链的情况怎么做 OI系列赛事的特殊性质分很 ...
- jenkins"控制台输出"乱码问题解决
今天在搭建Jenkins环境时,安装完Tomcat.Jenkins.创建项目进行构建后,在查看控制台输出时,结果中文全部显示乱码.然后呢,就是漫长的解决历程,最终呢,解决乱码问题的时间终于超过了环境搭 ...
- ProjectEuler215 Crack-free Walls
易知状态不会太多(\(3329\)个),直接搜一下,按照能不能连在后面建边,跑一遍dp即可 #include <bits/stdc++.h> using namespace std; st ...
- SpringBoot统一异常处理后TX-LCN分布式事务无法捕获异常进行回滚
通常我们使用SpringBoot都会进行统一异常处理,例如写一个BaseController,在BaseController里进行统一异常处理,然后其他的Controller都继承BaseContro ...