
algorithms(technology)
文章平均质量分 57
lwl_ls
这个作者很懒,什么都没留下…
展开
-
正负算法生成圆
正负法是利用平面曲线将平面划分成正负区域,对当前点产生的圆函数进行符号判别,利用负反馈调整以决定下一个点的产生来直接生成圆弧。 一、正负画圆算法描述 设要显示圆的圆心在原点(0,0),半径为R,初始点的坐标为(0,R),顺时针生成八分之一圆,令:F(x,y)=x2+y2-R2 则圆的方程为: F(x,y)=0转载 2008-02-16 09:29:00 · 5429 阅读 · 1 评论 -
Fibonacci相关题目
请分别设计一个递归和非递归算法来计算F(n) F列可递归定义为: n为大于等于0的整数 F(n)=n 当n=0,1,2 F(n)=F(n-1) - F(n-3) 当n>=3 const int Max=1000000;bool got[Max];int gotVal[Max];int Cal(int原创 2008-01-12 09:49:00 · 724 阅读 · 0 评论 -
1000!的位数
精确计算这个大数阶乘的位数我还做不到,但估算一下还是可以做到的。说说我自己的看法。一个自然数N,它的位数等于lgN+1。lg就是以10为底的对数。例如250 = 2.5*10^2,则lg250 = 2 + lg2.5,而lg2.5小于1,所以数250的位数约等于lg250+1,忽略小数部分,就等于3。所以1000!的位数约等于lg1000!+1lg1000! = lg1+lg2+lg3+……+lg转载 2008-01-19 10:35:00 · 1147 阅读 · 0 评论 -
求一个字符串中连续出现次数最多的子串
发信人: RoBa269 (roba), 信区: Algorithm标 题: Re: 请教:求一个字符串中连续出现次数最多的子串发信站: 水木社区 (Tue Apr 29 19:41:59 2008), 站内我有一个时间O(n^2),空间O(n)的算法枚举连续子串的起点,这样问题变成了,求一个字串的前缀最多是重复了多少次得到的。这个问题可以用KMP算法的结果得出。跑一遍KMP,求出那个失配以后向转载 2008-05-01 01:04:00 · 939 阅读 · 0 评论 -
heapsort
#includeiostream>using namespace std;void DownAdjust(int *a, int first, int last)...{ int tmp,down; tmp = a[first]; for(down = first*2+1; down last; down=down*2+1)...{// if(downa[down+1])原创 2008-05-03 16:38:00 · 655 阅读 · 0 评论 -
错排问题的递推解决
http://blog.programfan.com/article.asp?id=17413也谈“装错信封问题” 广东省江门一中 王 旭( 529000 ) 颜书先生《“装错信封问题”的数学模型与求解》一文(见《数学通报》 2000 年第 6 期 p.35 ),给出了该经典问题的一个模型和求解公式: 编号为 1 , 2 ,……, n 的 n 个元素排成一列,若每个元素所处位置转载 2008-04-30 10:34:00 · 1862 阅读 · 0 评论 -
Trie Tree and some DS&Athm sample
http://www.blogjava.net/wqnashqu/archive/2007/12/13/167586.htmlTrie Tree and some DS&Athm sample Trie树的定义(转)Trie树是一棵度 m ≥ 2 的树,它的每一层分支不是靠整个关键码的值来确定,而是由关键码的一个分量来确定。如下图所示Trie树,关键码由英文字母组成。它包括两类结点:元转载 2008-05-03 18:35:00 · 1689 阅读 · 0 评论 -
trie 树
http://www.cppblog.com/zoyi-hang/archive/2008/04/06/46355.htmltrie 树好不容易写的一个模版~本来是想按照我们数据结构教程的trie树来写,但是他的实现我实在觉得太难所以还是采用简化版的trie树这个应该算是比较标准的trie树结构,但是他的插入实现起来不仅仅是插入本身的单词,可能还需要修改原来的数结构比如说本身已经存在了转载 2008-05-03 19:15:00 · 955 阅读 · 0 评论 -
MaxSection 最长平台
#includeusing namespace std;int MaxSection(int *a, int n){ int max,i,sum; max=-200000000; sum=0; for(i=0;i sum=sum+a[i]; if(sum>max) max=sum; if(sum } return max;}void main(){ int a[]={2,2,3,原创 2008-05-03 19:33:00 · 777 阅读 · 0 评论 -
算法是百度工程师的利器
算法是百度工程师的利器2007年05月20日 星期日 17:47 “工欲善其事,必先利其器”,对于百度工程师来说,算法就是他们解决难题的利器。为什么这么说?因为百度搜索引擎研发的各个环节都离不开算法。我们需要快速,准确、实用、创新和不断改进的算法来满足用户的需求。 百度面对的是转载 2008-05-24 10:02:00 · 1071 阅读 · 0 评论 -
org.apache.lucene.search.Hits.java搜索索引
/** * Tries to add new documents to hitDocs. * Ensures that the hit numbered min has been retrieved. */ private final void getMoreDocs(int min) throws IOException { if原创 2008-10-28 20:45:00 · 2987 阅读 · 0 评论 -
算法导论题解(我的答案,欢迎指正) introduction to algorithms
online reading: http://books.google.com/books?id=NLngYyWFl_YC&pg=PA15&dq=introduction+to+algorithms&psp=1&sig=jX-xfEDWJU3PprUwH8Qfxidli6M#PPA382,M1*******************chp11.2-11.2-21.2-3 n=原创 2008-12-14 09:50:00 · 3599 阅读 · 1 评论 -
google code jam 08 资格赛A题
#include#include#includeusing namespace std;const int hash_size = 199;unsigned int ELFHash( char * str) { unsigned int hash = 0 ; unsigned int x = 0 ; whi原创 2009-08-30 19:47:00 · 654 阅读 · 0 评论 -
gcj 08 r1A-large
#include#includeusing namespace std;inline int cmp (const void *a, const void *b){ long long aa = *(long long *)a; long long bb = *(long long *)b; return (aa bb) ? 1 : 0;}v原创 2009-08-30 21:49:00 · 564 阅读 · 0 评论 -
09GCJ r1-3rd-A all your base
// 2009 GCJ round1-3rd-A: all your base#include #include #include using namespace std;int main(){ int T; scanf("%d", &T); char ch; scanf("%c", &ch); int i; for(i = 0; i < T原创 2009-09-20 00:19:00 · 643 阅读 · 0 评论 -
hash_map构造函数设与不设初始bucket数的区别
根据hash_map的实现进行理论猜测,不设初始bucket数时,插入是会比较慢的。实际测试证实如果设置合适的初始bucket数效率较高,快1倍左右。 ============================================ 不设初始bucket数时 #include #include #include using namespace __gnu_原创 2010-04-25 15:47:00 · 1215 阅读 · 0 评论 -
Big number multiplication 大整数乘法
const int N=1100;struct BigNum...{ int front; int data[N+1];};BigNum& Mulit(BigNum up, BigNum down)...{ int i,k,carry,v; BigNum prod; prod.front=up.front+down.front-N+1; for(i=prod.front;iN;i+原创 2008-01-05 09:25:00 · 1295 阅读 · 0 评论 -
Permutation available for duplicate element
const int N=10;int pcnt[N], u_cnt;char s[N],ps[N];void Permu(char *pch, int *pint){ char *pch2=pch; int *pint2=pint; while(pch2 swap(pch, pch2), swap(pint, pint2); (*pint)--; if(*pint==0)原创 2008-01-01 12:48:00 · 689 阅读 · 0 评论 -
后缀树与后缀数组zz
function StorePage(){d=document;t=d.selection?(d.selection.type!=None?d.selection.createRange().text:):(d.getSelection?d.getSelection():);void(keyit=window.open(http://www.365key.com/storeit.a转载 2007-11-26 18:07:00 · 1424 阅读 · 0 评论 -
链表归并排序
Node* MergeSortLinks(Node *h, int n)...{ if(n1) return; int n1,n2,i,t1=0,t2=0; Node *h1,*h2,*hh=NULL,*cur=NULL,*p; n1=n/2, n2=n-n1; p=h; for(i=0;in1;i++) p=p->next; h1=MergeSortLinks(h,n1);原创 2007-12-03 10:48:00 · 1508 阅读 · 0 评论 -
KMP
void KMP_MatcherJ(char *T, int nt, char *p, np){ int i,k; int *x=new int[np+1]; // because p[] begins at index 1 PrefixFun(p, np, x); k=0; for(i=1;i while(k>0 && p[k+1]!=T[i]) k=x[k];原创 2007-12-03 10:56:00 · 738 阅读 · 0 评论 -
字符串 左移I个位置
void Reverse(char *s,int L,int H)...{ while(LH)...{ swap(s[L],s[H]); L++, H--; }}void ShiftI(char *s, int n, int i)...{ // abc1234->cba4321->1234abc Reverse(s,0,i-1); Reverse(s,i,n-1); R原创 2007-12-09 09:48:00 · 832 阅读 · 0 评论 -
sample N个数中随机选M个
void RandomSelectMofN(int *a, int N, int M)...{ // pls refer to Knuths TAOCP int n; srand(unsigned(time(NULL))); for(n=N;n>0;n--)...{ if( rand()%n M )...{ // assume bigrand. coutN原创 2007-12-09 00:38:00 · 1170 阅读 · 0 评论 -
suffix array written by myself
Problem: we want to match string P in string T.len(P)==m, len(T)==nDoubling Algorithm to construct suffix array: O(nlbn) (lb:log2)To match the P in T: O(m+lbn)原创 2007-12-12 09:15:00 · 641 阅读 · 0 评论 -
search the longest common substr in 2 strings
不知道是MS推出了新技术对我的引导还是自己一直认为自己要有所人生的突破的源由,想开发一套ERP系统,以后没有钱了好坐在家里卖(~_~),想开发一些基于条形码系列的软件,因为最近两年都是在修改与条码枪与PLC有关的自动化控制方向的软件系统,但感觉这方便技术已经比较成熟且新技术要出来也比较慢,如果你要认真学习的话,做这方面也很容易,没有什么技术优势可言,现在做PC应用方向开发的人越原创 2007-12-12 21:24:00 · 567 阅读 · 0 评论 -
启发式搜索算法引论------A*算法理论与实践
启发式搜索算法引论------A*算法理论与实践 下面是作者的email:EmilMatthew (EmilMatthew@126.com) 英文出处:http://blog.youkuaiyun.com/EmilMatthew/archive/2006/10/17/1338808.aspx[ 类别 ]算法实践 ,人工智能[推荐指数]★★★★★[ 摘要 ]本文介绍了转载 2007-12-13 11:32:00 · 1181 阅读 · 0 评论 -
complexity of judging n numbers is sorted or not
my analysis:n! permutations.i times comparation for a permutation.i=1: 1*sikma(k=n to 2)* C(k-1,1)*(n-i-1)! comparations...i=t: t*sikma(k=n to i+1)*C(k-1,t)*(n-t-1)!...i=n-1: (n-1)*sikma(k=n to原创 2007-12-15 00:02:00 · 672 阅读 · 0 评论 -
DFS
struct node...{ int id; int w; node* next;};struct arr_node...{ int id; node* head;};arr_node a[N];int color[N],d[N],f[N],from[N],time;void Init()...{ int i; for(i=0;in;i++)...{ color[i]=0原创 2007-12-15 14:51:00 · 672 阅读 · 0 评论 -
Young tableau 矩阵搜索的时间复杂度
function go(url) { window.open(url, "_self"); } function OpenInNewWindow(url) { go(url); } <!-- var L_UNDEFINED_TEXT = "“帮助”找不到此内嵌定义。";function Inlin原创 2007-12-14 09:39:00 · 1289 阅读 · 0 评论 -
implementation of bitmap
#define shift 5#define tail 0x1F#define bitword 32#define N 10000000int a[1+N/bitword];void Set(int i){ a[i>>shift] |= 1}void Clr(int i){ a[i>>shift] &= ~(1}int test(int i){ return a[i>>shift原创 2007-12-14 10:03:00 · 600 阅读 · 0 评论 -
get quotient without division and multiplication
unsigned int NDivide3(unsigned int n)...{ unsigned int ans=0,i,b; while(n>3)...{ b=n>>2; ans+=b; n=n^3+b; } if(3==n) return ++ans; else return ans;}原创 2007-12-17 09:12:00 · 567 阅读 · 0 评论 -
Search Techniques 搜索方式
原文:http://www.oiers.cn/usaco%20training/11-401.asp.htm样例: n 皇后问题 [经典问题]将 n 个皇后摆放在一个 n x n 的棋盘上,使得每一个皇后都无法攻击到其他皇后。深度优先搜索 (DFS)显而易见,最直接的方法就是把皇后一个一个地摆放在棋盘上的合法位置上,枚举所转载 2007-12-22 10:57:00 · 1594 阅读 · 0 评论 -
常见的搜索优化策略
现在acm的难度不断增加,简单的常规的搜索算法,(因为这些搜索的本质是盲目搜索)已经不能很好地解决问题,下面介绍 一些常见的优化方式首先是深度优先搜索,对于DFS的优化主要是在时间复杂度上的,方法也有很多种,但是无论是何种优化方式,其本质都是通过减少扩展点的数量来降低时间复杂度的,当然减少的只能是那些不含可行解,或是不含最优解的状态。常见的优化方式主要有以下几种:1.剪枝 当我们发现某转载 2007-12-22 12:55:00 · 1662 阅读 · 0 评论 -
一致性hash服务器调整影响面的概率分析
负载均衡 一致性哈希 consistent hashing原创 2010-06-08 19:40:00 · 611 阅读 · 0 评论