算法竞赛
文章平均质量分 59
新的飞扬
这个作者很懒,什么都没留下…
展开
-
一些竞赛算法题目及解答(角谷步数,数组非排序正负数分离, 最小方差生成树)
1 角谷步数你听说过角谷猜想吗?任意的正整数,比如 5, 我们从它开始,如下规则计算:如果是偶数,则除以2,如果是奇数,则乘以3再加1.如此循环,最终必会得到“1” !比如 5 的处理过程是:5168421一个正整数经过多少步才能变成1, 称为角谷步数。对于5而言,步数也是5对于1,步数为0本题的要求是,从标准输入给定一个整数n(1int ComputStep(unsigned int n) {原创 2013-04-12 22:16:37 · 1519 阅读 · 0 评论 -
字典树的应用 单词意义查找-C语言实现
/* 字典树应用,快速单词查找 */ const int M = 1000000; char word[1000000][11]; int wp; // 单词列表的下标 struct node{ int next[26]; int value; bool end; } tree[M]; // 可用节点数组,相当于内存池 int pi = 1; // 代表空闲的节点位置 void i原创 2015-07-16 17:14:57 · 1384 阅读 · 0 评论 -
AC自动机应用 多模式匹配 多个单词在文章中出现的次数-C语言实现
/*AC自动机应用 多模式匹配 多个单词在文章中出现的次数*/ #define N 500 char str[1000],keyword[51]; int head,tail; // 表示字典树的一个节点 struct node{ node * fail; node * next[26]; int count; node(){ fail = NULL; count = 0;原创 2015-07-17 11:28:48 · 815 阅读 · 0 评论 -
KMP算法-C语言程序实现
////////////////////////////////////////////////// /*KMP算法*/ #include #include #include using namespace std; void getNext(char a[],int next[]){ int i,j; next[1] = 0; j = 0; i = 2; int m = strle原创 2015-07-16 17:03:44 · 1899 阅读 · 0 评论 -
数的排列的递归实现-C++ STL实现
#include #include #include "iterator" #include "algorithm" #include "string" #include "stdio.h" using namespace std; ostream_iterator oi(cout,""); int icount = 0; void pailie(vector vectNum,vector &原创 2015-07-16 17:21:34 · 484 阅读 · 0 评论