POJ1007】的更多相关文章

这题比较简单,重点应该在如何减少循环次数. package practice; import java.io.BufferedInputStream; import java.util.Map; import java.util.Scanner; import java.util.TreeMap; /** * DNA sorting * * @author caiyu * @date 2014-11-5 */ public class POJ1007 { public static void m…
http://poj.org/problem?id=1007 (题目链接) 题意 给出m个字符串,将其按照逆序对个数递增输出. Solution 树状数组经典应用. 代码 // poj1007 #include<algorithm> #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #include<st…
[POJ1007]DNA Sorting 试题描述 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 fo…
这道题比较简单,但通过这个题我学会了使用c++内置的qsort函数用法,收获还是很大的! 首先简要介绍一下qsort函数. 1.它是快速排序,所以就是不稳定的.(不稳定意思就是张三.李四成绩都是90,张三成绩在前:排序完毕后有可能变成李四的90在前,张三在后) 2.需要包含头文件:cstdlib 3.原型:void qsort(void *base,int nelem,int width,int(*fcmp)(const void*,const void *)); 4.参数:数组首地址,数组内元…
求逆序数,快排 public static void acm1007(int a, string[] c) { Dictionary<int, string> dic = new Dictionary<int, string>(); int[] i = new int[a]; ; foreach (var item in c) { int k = Acm1007Unit(item); if (!dic.ContainsKey(k)) { i[j] = k; j++; dic.Add…
2014-08-22   题目意思: 按照各个字符串的逆序数排序(稳定排序,即若A=B,则AB的顺序还是原来的样子) 思路: 求出每个字符串的逆序数后,排序输出即可 代码: //Memory Time // 352K 16MS #include <stdio.h> #include <stdlib.h> typedef struct Dna{ int num; ]; }DNASQ; //计算逆序数 int count(char sq[],int len){ int a,c,g,i;…
int InversionNumber(char* s,int len) { int ans=0;  //s逆序数 int A,C,G;  //各个字母出现次数,T是最大的,无需计算T出现次数 A=C=G=0; for(int i=len-1;i>=0;i--) { switch(s[i]) { case 'A':A++;break;  //A是最小的,无逆序数 case 'C': { C++; ans+=A;  //当前C后面出现A的次数就是这个C的逆序数 break; } case 'G':…
DNA排序 逆序数可以用来描述一个序列混乱程度的量.例如,“DAABEC”的逆序数为5,其中D大于他右边的4个数,E大于他右边的1个数,4+1=5:又如,“ZWQM”的逆序数为3+2+1+0=6. 现在有许多长度一样的字符串,每个字符串里面只会出现四种字母(A,T,G,C).要求编写程序,将这些字符串按照他们的逆序数进行排序. 输入: 输入数据有多组,以EOF结束.其中,每组数据: 第一行包括两个正整数,第一个正整数N给出了字符串的长度,第二个正整数M给出了字符串的数量.(1<=N,M<=10…
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…
ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜鸟之作,大牛勿喷,如有不当或补充之处,欢迎指出. 本建议书分为三个阶段,大一.大二.大三.大四暂没整理,一方面是大四要面临考验和找工作的问题,坚持继续acm的很少,另一方面,本人还没大四…… 下面以个人经验分析一下这三个阶段建议学习的内容和具体的训练计划. 正文: 大一(第一阶段): 大一是时间最充…