poj1007 -- DNA Sorting

POJ1007 DNA Sorting中英对照翻译与参考解答 POJ 1007 DNA Sorting中英对照翻译与参考解答 阅读详情

DNA Sorting
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 100566 Accepted: 40371

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. 

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 (0 < 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''. Since two strings can be equally sorted, then output them according to the orginal order.

Sample Input

10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT

Sample Output

CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA
思路就是创建一个结构体保存数据,求出每一个DNA的measure,然后根据measure从小到大排序,最后输出。

代码如下:

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;

struct Node
{
    string DNA;
    int measure;

    Node(string str,int mea):DNA(str),measure(mea){}
};

bool cmp(Node node1,Node node2)  //按measure从小到大排序
{
    return node1.measure<node2.measure;
}

vector<Node> v;

int main()
{
    //freopen("test.txt","r",stdin);
    v.clear();
    int n,m;
    scanf("%d%d",&n,&m);
    while(m--)
    {
        string str;
        cin>>str;
        int measure=0;
        int len=str.length();
        for(int i=0;i<len-1;i++)
        {
            for(int j=i+1;j<len;j++)
            {
                if(str[i]>str[j])
                    measure++;
            }
        }
        Node node(str,measure);
        v.push_back(node);
    }
    sort(v.begin(),v.end(),cmp);
    for(int i=0;i<v.size();i++)
        cout<<v[i].DNA<<endl;
    return 0;
}
归与分治策略实例编程 统计给定数组中的逆序对个数 统计给定数组中的逆序对个数。 给n个数a1,a2…an,如果存在存在ai>aj,且i<j,则称这样的元素对为一个逆序对 统计这n个数中逆序对的总数 比如说,n=5,a1到a5分别为5,3,1,4,3 则逆序对有 ,,,,,共6对 立即下载

相关推荐

EWF写保护功能详解:从安装到实战操作指南

本文详细介绍了EWF写保护功能的安装与实战操作指南。EWF(Enhanced Write Filter)通过重定向写入操作保护硬盘分区,特别适合需要长期稳定运行的系统场景。文章涵盖从安装准备、图形界面操作到命令行高级管理的全流程,并提供了常见问题的解决方案,帮助用户轻松掌握这一实用工具。

weixin_28710999的博客 451

DNA Sorting

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 sequenceDAABEC’’, this measure i...

无限迭代中...... 589

frp 内网渗透案例:端口转发 + 二级代理(深入理解 frp 在内网渗透中的技巧)

本文使用 vulnstack7 靶场作为测试环境,解释 frp 内网渗透特殊使用姿势,通过此案例来提高内网渗透能力。接下来的演示环境只做了以下修改。攻击者 vps 的 ip 修改为:192.168.72.162。DMZ 区域的 ubuntu 的 ip1 修改为:192.168.72.129。先引入问题,当我们控制了 DMZ 的 ubuntu 并且拿到第二层网络的 ubuntu 的 rce 后,会出现以下两个问题。如何搭建隧道让 ubuntu 反弹 shell 给攻击者 vps?

anddddoooo的博客 1773

1198: DNA Sorting

题目DescriptionOne 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

光光的小屋 379

xhs私信协议分析

之前分析过xhs的shield算法,今天再聊聊xhs的私信,文章仅供学习参考研究交流,如有侵权请联系删帖。经过抓包分析发现私信接口并不是走的http协议,而是socket协议。而要获取socket包则需要使用wireshark软件1、protobuf的包体中的序号7,多次验证后发现文字信息的需要需要固定成12、protobuf的包体中的序号12,多次验证后发现文字信息的需要需要固定成1后续有时间的话,再研究一下视频和图片格式的私信协议,这次就分析到这里吧。

佛系更新... 3501

FPGA实战:AXI BRAM Controller写时序避坑指南(附Vivado配置步骤)

本文深入探讨了FPGA开发中AXI BRAM Controller的写时序实战要点与常见陷阱。文章聚焦于写地址与写数据通道的握手机制,详细解析了AWREADY、WVALID等关键信号的处理,并提供了Vivado中流水线深度、ECC等关键参数的配置步骤与优化建议,旨在帮助开发者有效规避时序问题,提升系统性能。

weixin_32306683的博客 176

1007 DNA Sorting

DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 60694   Accepted: 23968 Description One measure of ``unsortedness'' in a sequence is the number

Stay foolish, stay hungry 526

WRF和WPS安装和编译时遇到的问题

检查是否自己netcdf和Fortran编译器一致。解决办法:修改configure.wps里的路径。如果没问题且wrf已成功编译,考虑重新。path修改为jasper在的路径。

m0_54898744的博客 1841

DNA Sorting(水题)

DescriptionOne 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 measu...

Baiyi_destroyer的博客 1165

GEPA_AIME教程:使用GEPA优化数学问题求解的完整指南

本教程展示了如何使用DSPy框架中的GEPA(Generative Evolutionary Prompt Adaptation)优化器来提升大语言模型在数学竞赛问题(AIME)上的表现。# 创建基础的链式思考程序"""带有详细反馈的评估指标,为GEPA提供学习信号"""try:# 处理解析错误feedback_text = f"最终答案必须是一个有效的整数。你回答了'

步子哥的博客 1391

2026年广东省职业院校技能大赛中职组“大数据应用与服务”样题一完整参考答案

2026年广东省职业院校技能大赛中职组“大数据应用与服务”样题一完整参考答案

我是网络安全兼技能大赛工程师,专注网络安全技术学习与技能大赛实战!持续分享最新的技术文章,帮你少走弯路,一起在技术赛道上进步~ 785

PKU1007

DNA Sorting Time Limit:1000MS  Memory Limit:10000KTotal Submit:17097 Accepted:6588 DescriptionOne measure of ``unsortedness in a sequence is the number of pairs of entries that are out of order wi

Wigou Lau 1086

YOLOv11 改进 - Mamba | 集成Mamba-YOLO(AAAI 2025),Mamba-YOLOv11-B 替换骨干,破解全局依赖建模难题,实现高效实时检测

本文介绍Mamba YOLO,为图片物体识别提供了“又快又准”的新方案。传统CNN架构运行快但难以捕捉远距离关联物体,Transformer架构精度高但计算量呈平方级增长,而SSM虽计算量为线性级且能抓全局关联,但用于图片识别时细节定位不准。为此,Mamba YOLO做了三项关键优化:引入ODMamba骨干网络,解决自注意力的二次复杂度问题,且无需预训练;设计ODMamba宏观结构确定最佳阶段比例和缩放大小;采用多分支结构的RG块建模通道维度,解决SSM在序列建模中的不足。在COCO数据集测试中,其小版本推

魔改工程师的博客 863

POJ1007-DNA Sorting

DNA Sorting Time Limit:1000MS Memory Limit:10000K Total Submissions:112218 Accepted:44884 Description One measure of ``unsortedness'' in a sequence is the number of pairs of ...

s0il的博客 630

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

POJ1007 DNA Sorting

DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 85026   Accepted: 34238 Description One measure of ``unsortedness'' in a sequence is the number

长风的专栏 967

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

POJ 1007 DNA Sorting

POj 1007,属于快速排序吧,下面为题目大意 序列“未排序程度”的一个计算方式是元素乱序的元素对个数。例如:在单词序列“DAABEC'”中,因为D大于右边四个单词,E大于C,所以计算结果为5。这种计算方法称为序列的逆序数。序列“AACEDGG”逆序数为1(E与D)——近似排序,而序列``ZWQM''逆序数为6(它是已排序序列的反序)。 ...

diaobin0154的博客 283

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

POJ-1007:DNA Sorting

1007:DNA Sorting 时间限制:  1000ms  内存限制:  65536kB 描述 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

精灵的博客 4554

POJ-1007 DNA Sorting

POJ-1007 DNA Sorting 题目链接: 题目大意:序列“未排序程度”的一个计算方式是元素乱序的元素对个数。例如:在单词序列“DAABEC’”中,因为D大于右边四个单词,E大于C,所以计算结果为5。这种计算方法称为序列的逆序数。序列“AACEDGG”逆序数为1(E与D)——近似排序,而序列``ZWQM’’ 逆序数为6(它是已排序序列的反序)。 你的任务是分类DNA字符串(只有ACGT...

鱼头的水题之路 291

POJ 1007 DNA Sorting

POJ   1007   DNA Sorting                   题目链接:

slicer的技术交流栈 1183

POJ 1007 Java:DNA Sorting

题目描述:大意是给出一些相同长度的字符串,根据这些字符串的逆序数进行排序,输出。 分析:定义一个DNA类,其中包含字符串和该字符串的逆序数两个成员变量,和相关成员函数。对给定的字符串排序,再输出。 AC代码: import java.util.*; public class POJ1007 { public static void main(String[] args){

卡卡罗特 1194

POJ 1007 DNA Sorting

一、题目信息 DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 68122   Accepted: 27076 Description One measure of ``unsortedness'' in a sequence i

FreeCoder的专栏 2546

[POJ 1007] DNA Sorting C++解题

DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 77786 Accepted: 31201 Description One measure of ``unsortedness'' in a sequence is the...

diankong6347的博客 334

[POJ][1007]DNA Sorting

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 m

软件工程学森 1653

poj 1007 DNA Sorting

poj 1007 DNA Sorting题意:将字符串以逆序数的大小排序。 题解:rt。#include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> #include <iostream> using namespace std; struct xx { char str[51]; int

学无纸巾 307
上一篇: poj1006 -- 生理周期
下一篇: poj1008 -- 玛雅历
BestFSQ
博客等级 码龄10年 24粉丝 35原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值