博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ1007(DNA Sorting)
阅读量:4601 次
发布时间:2019-06-09

本文共 713 字,大约阅读时间需要 2 分钟。

求逆序数的题。因为只有4种元素,所以可以直接统计排在某个元素前面且比它小的元素个数(用4个变量记录已出现的A,C,G,T的个数),复杂度为O(N)。若元素种类很多,可以使用树状数组进行类似基数排序的统计。

View Code
1 #include 
2 #include
3 #define N 55 4 #define M 105 5 struct node 6 { 7 char s[N]; 8 int d; 9 }node[M];10 int a,c,g,t,len;11 int cal(char s[])12 {13 int i,sum;14 a=c=g=t=0;15 sum=0;16 for(i=0;i
d;32 y=((struct node*)b)->d;33 if(x!=y) return x>y?1:-1;34 else return (struct node*)a-(struct node*)b;35 }36 int main()37 {38 int i,m;39 while(~scanf("%d%d",&len,&m))40 {41 getchar();42 for(i=0;i

 

转载于:https://www.cnblogs.com/algorithms/archive/2012/04/18/2454748.html

你可能感兴趣的文章
【云计算】使用supervisor管理Docker多进程-ntpd+uwsgi+nginx示例最佳实践
查看>>
Ubuntu16.04下配置ssh免密登录
查看>>
实验二 2
查看>>
will-change属性
查看>>
android学习笔记54——ContentProvider
查看>>
Unity3d android开发之触摸操作识别-双击,滑动去噪处理
查看>>
Custom view * is not using the 2- or 3-argument View constructors; XML attributes will not work
查看>>
模型选择准则
查看>>
安卓动态增加按钮
查看>>
iOS7程序后台运行
查看>>
maven+testng+reportng的pom设置
查看>>
IT telephone interview
查看>>
gitlab安装配置
查看>>
ps载入画笔
查看>>
悲怆:IT人的一声叹息->一个程序员的自白[转帖]
查看>>
[SpringMVC]自定义注解实现控制器访问次数限制
查看>>
日记(序)
查看>>
A == B ?
查看>>
洛谷P3763 [Tjoi2017]DNA 【后缀数组】
查看>>
UVa 442 Matrix Chain Multiplication(矩阵链,模拟栈)
查看>>