假期学习第一步之......学习堆排序
    
            
摘要:堆:分为小根堆和大根堆,就是说堆根的元素的关键字最小(最大);堆排序:Heapsort;时间复杂度:O(nlogn);优点:当题目描述只是说输出第K大或者是最大的数据的时候比快排有优势。快排的时间复杂度为O(nLogn),但是如果是堆排序的话时间复杂度为O(klogn),如果k<<n那么还是选择堆 排序;步骤:1>将待排序size个数据存储在数组内。如果下标2*i<size,那么2*i为i的左子树;如果2*i+1<size,那么2*i+1为i的右子树;2>建立初始堆。从最后一个非叶子节点开始调整,就是size/2。如果是想建小根堆的,建的初始堆堆根元素最大;
        
阅读全文
                posted @ 
2013-01-06 17:54 
crying_Dream
        
阅读(227) 
         
        推荐(0)     
             
            
            
    【字典树】
    
            
摘要:HDU 1251http://acm.hdu.edu.cn/showproblem.php?pid=1251Problem DescriptionIgnatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀).Input输入数据的第一部分是一张单词表,每行一个单词,单词的长度不超过10,它们代表的是老师交给Ignatius统计的单词,一个空行代表单词表的结束.第二部分是一连串的提问,每行一个提问,每个提问都是一个字符串.注意:本题只有一组测试数据,处理到文件结束.Output对于每个提问,
        
阅读全文
                posted @ 
2012-11-05 22:17 
crying_Dream
        
阅读(222) 
         
        推荐(0)     
             
            
            
    hash
    
            
摘要:POJ 1840 Eqshttp://poj.org/problem?id=1840DescriptionConsider equations having the following form:a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0The coefficients are given integers from the interval [-50,50].It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0
        
阅读全文
                posted @ 
2012-11-05 20:13 
crying_Dream
        
阅读(291) 
         
        推荐(0)     
             
            
            
    【转】链表经典问题总汇
    
            
摘要:转自:http://blog.csdn.net/vividonly/article/details/6673758收集了一下链表常见的面试题:1、如何判断一个单链表有环2、如何判断一个环的入口点在哪里3、如何知道环的长度4、如何知道两个单链表(无环)是否相交5、如果两个单链表(无环)相交,如何知道它们相交的第一个节点是什么6、如何知道两个单链表(有环)是否相交7、如果两个单链表(有环)相交,如何知道它们相交的第一个节点是什么1、采用快慢步长法。令两个指针p和q分别指向头结点,p每次前进一步,q每次前进两步,如果p和q能重合,则有环。可以这么理解,这种做法相当于p静止不动,q每次前进一步,所有肯
        
阅读全文
                posted @ 
2012-09-03 14:16 
crying_Dream
        
阅读(229) 
         
        推荐(0)     
             
            
            
    ZOJ 3633 Alice's present【线段树】
    
            
摘要:As a doll master, Alice owns a wide range of dolls, and each of them has a number tip on it's back, the tip can be treated as a positive integer. (the number can be repeated). One day, Alice hears that her best friend Marisa's birthday is coming , so she decides to sent Marisa some dolls for
        
阅读全文
                posted @ 
2012-08-29 19:20 
crying_Dream
        
阅读(205) 
         
        推荐(0)     
             
            
            
    ZOJ 3643 Keep Deleting【KMP+栈模拟】
    
            
摘要:Assume that string A is the substring of string B if and only if we can find A in B, now we have a string A and another string B, your task is to find a A in B from B's left side to B's right side, and delete it from B till A is not a substring of B, then output the number of times you do th
        
阅读全文
                posted @ 
2012-08-27 20:32 
crying_Dream
        
阅读(424) 
         
        推荐(0)     
             
            
            
    关于 KMP
    
            
摘要:发现KMP, 我都已经忘了,找到我之前写的总结,粘贴一下,保存留念吧; 发现之前我写的总结和你好玩的样子,自己都看笑了...hia hia hia hia...KMP我只了解你一点点KMP:即串模式匹配,(KMP分别是三个人名字的简称)。学习KMP推荐:严蔚敏数据结构课件。真心说她讲的很到位。能让你明白next[],的求法。简单算法基本思想(当字符串长度不大时):用i, j指主串和模式串。通过一个个比较,直至模式串与主串一一匹配则称匹配成功,否则失败。改进办法:不用将i指针一次次回朔,而是利用以匹配的结果是是模式串尽可能的向前滑动。 这里需要一个next[100], 的函数。函数模板:K...
        
阅读全文
                posted @ 
2012-08-27 20:20 
crying_Dream
        
阅读(190) 
         
        推荐(0)     
             
            
            
    ZOJ 3635 Cinema in Akiba【树状数组+二分查找】
    
            
摘要:Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is full of people. The layout of CIA is very interesting, as there is only one row so that every audience can enjoy the wonderful movies without any annoyance by other audiences sitting in front of him/her.
        
阅读全文
                posted @ 
2012-08-26 21:38 
crying_Dream
        
阅读(444) 
         
        推荐(0)     
             
            
            
    ZOJ Information Sharing 【并查集+set】
    
            
摘要:There is going to be a test in the kindergarten. Since the kids would cry if they get a low score in the test, the teacher has already told every kid some information about the test in advance.But the kids are not satisfied with the information teacher gave. They want to get more. On the testing d..
        
阅读全文
                posted @ 
2012-08-26 20:31 
crying_Dream
        
阅读(278) 
         
        推荐(0)     
             
            
            
    POJ 2001 Shortest Prefixes【第一棵字典树】
    
            
摘要:DescriptionA prefix of a string is a substring starting at the beginning of the given string. The prefixes of "carbon" are: "c", "ca", "car", "carb", "carbo", and "carbon". Note that the empty string is not considered a prefix in 
        
阅读全文
                posted @ 
2012-08-13 10:11 
crying_Dream
        
阅读(380) 
         
        推荐(0)     
             
            
            
    字典树【模板】
    
            
摘要:字典树:也是trie树,根节点不包含字符,除了根节点外每个节点包含一个字符,而且都不一样。从根结点单到某结点的连线就是所对应的字符串。可以查找,插入和删除。实现过程:从根节点开始,查找第一个单词,找到后再找相应的子树进行循环这个过程...模板如下:struct node{ int cnt; //记录该字符出现次数 node *next[27];}*root; //root根节点 void Maketree(char *str) /*插入*/{ int ans, i, len; node *p, *q; p=root; len=strl...
        
阅读全文
                posted @ 
2012-08-13 10:08 
crying_Dream
        
阅读(193) 
         
        推荐(0)     
             
            
            
    POJ 3264 Balanced Lineup【RMQ-ST算法-区间最值】
    
            
摘要:DescriptionFor the daily milking, Farmer John'sNcows (1 ≤N≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things simple, he will take a contiguous range of cows from the milking lineup to play the game.
        
阅读全文
                posted @ 
2012-08-11 17:58 
crying_Dream
        
阅读(167) 
         
        推荐(0)     
             
            
            
    POJ 3250 Bad Hair Day【单调栈】
    
            
摘要:DescriptionSome of Farmer John'sNcows (1 ≤N≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads.Each cowihas a specified heighthi(1 ≤hi≤ 1,000,000,000) and is stan
        
阅读全文
                posted @ 
2012-08-11 15:21 
crying_Dream
        
阅读(493) 
         
        推荐(0)     
             
            
            
    POJ 2823 Sliding Window【单调对列经典题目】
    
            
摘要:DescriptionAn array of sizen≤ 106is given to you. There is a sliding window of sizekwhich is moving from the very left of the array to the very right. You can only see theknumbers in the window. Each time the sliding window moves rightwards by one position. Following is an example:The array is[13-1-
        
阅读全文
                posted @ 
2012-08-11 11:02 
crying_Dream
        
阅读(160) 
         
        推荐(0)     
             
            
            
    HLG 1522 子序列的和【队列的应用】
    
            
摘要:Description输入一个长度为n的整数序列(A1,A2,……,An),从中找出一段连续的长度不超过m的子序列,使得这个子序列的和最大。Input有多组测试数据,不超过20组测试数据。对于每组测试的第一行,包含两个整数n和m(n,m<=10^5),表示有n个数,子序列长度限制为m,表示这个序列的长度,第二行为n个数,每个数的范围为[-1000, 1000]。Output对于每组测试数据,输出最大的子序列和,并换行。Sample Input3 11 2 33 2-1000 1000 1Sample Output31001思路:看的比较懂得参考资料:http://blog.csdn.ne
        
阅读全文
                posted @ 
2012-08-11 10:58 
crying_Dream
        
阅读(341) 
         
        推荐(0)     
             
            
            
    HDU 1754 I hate it【线段树之单点替换区间最值】
    
            
摘要:Problem Description很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。Input本题目包含多组测试,请处理到文件结束。在每个测试的第一行,有两个正整数 N 和 M ( 0<N<=200000,0<M<5000 ),分别代表学生的数目和操作的数目。学生ID编号分别从1编到N。第二行包含N个整数,代表这N个学生的初始成绩,其中第i个数代表ID为i的学生的成绩。接下来有M行。每一行有一个
        
阅读全文
                posted @ 
2012-08-09 11:43 
crying_Dream
        
阅读(203) 
         
        推荐(0)     
             
            
            
    线段树模板【1】
    
            
摘要:单点增减,区间求和View Code struct Node { int l, r, mid, sum;}node[MAX]; void init(int a, int b, int n)//init(1,n+1,1); { node[n].l=a; node[n].r=b; node[n].mid=(a+b)/2; node[n].sum=0; if(a+1==b) return ; init(a, (a+b)/2; 2*n); init((a+b)/2, b, 2*n+1);}void add(int pos, int v...
        
阅读全文
                posted @ 
2012-08-09 11:38 
crying_Dream
        
阅读(120) 
         
        推荐(0)     
             
            
            
    推荐线段树资料
    
            
摘要:http://www.notonlysuccess.com/index.php/segment-tree-complete/
        
阅读全文
                posted @ 
2012-08-09 11:09 
crying_Dream
        
阅读(114) 
         
        推荐(0)     
             
            
            
    HDU 1166 临兵布敌【树状数组】
    
            
摘要:Problem DescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。中央情报局要研究敌人究竟演习什么战术,所以Tidy要随时向Derek汇报某一段连续的工兵营地一共有多少人,例如Derek问:“Tidy,马上汇报第3个营地到第10个营地共有多少人!”Tidy就要马上开始计算
        
阅读全文
                posted @ 
2012-08-09 08:14 
crying_Dream
        
阅读(230) 
         
        推荐(0)     
             
            
            
    POJ 2155 Matrix【二维树状数组】POJ 2155【
    
            
摘要:DescriptionGiven an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1 <= i, j <= N). We can change the matrix in the following way. Given a rectangle whose upper-left corner is (x1, y1) and lower-right cor
        
阅读全文
                posted @ 
2012-08-09 08:02 
crying_Dream
        
阅读(208) 
         
        推荐(0)