自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Keep Moving的专栏

Keep Moving

  • 博客(37)
  • 收藏
  • 关注

原创 Codeforces 311(div 2):E. Ann and Half-Palindrome

题目描述:          给定半回文子串的定义,现给你一个串S和一个整数K,输出S所有子串中且是半回文排名第K的子串,半回文子串按照字典序升序顺序。(len(S) 分析:             首先,定义dp[i][j]表示S[i....j]是否为半回文子串,可以在的时间内求出所有的状态。现在,需要计算排名第K的半回文子串,我们可以通过将所有的半回文子串插入到一颗字典树中

2015-07-08 13:12:00 1200

原创 unordered_set介绍

简介          C++ 11中出现了两种新的关联容器:unordered_set和unordered_map,其内部实现与set和map大有不同,set和map内部实现是基于RB-Tree,而unordered_set和unordered_map内部实现是基于哈希表(hashtable),由于unordered_set和unordered_map内部实现的公共接口大致相同,所以本文以u

2015-07-07 10:18:18 24829 8

原创 浅谈Manacher算法与扩展KMP之间的联系

首先,在谈到Manacher算法之前,我们先来看一个小问题:给定一个字符串S,求该字符串的最长回文子串的长度.对于该问题的求解,网上解法颇多,时间复杂度也不尽相同,这里列述几种常见的解法.解法一      通过枚举S的子串,然后判断该字串是否为回文,由于S的子串个数大约为,加上每次判断需要的时间,所以总的时间复杂度为,空间复杂度为.bool check(string &S, int l

2015-07-03 22:43:45 1083 2

原创 O(N)的素数筛选法和欧拉函数

首先,在谈到素数筛选法时,先涉及几个小知识点.1.一个数是否为质数的判定.质数,只有1和其本身才是其约数,所以我们判定一个数是否为质数,只需要判定2~(N - 1)中是否存在其约数即可,此种方法的时间复杂度为O(N),随着N的增加,效率依然很慢。这里有个O()的方法:对于一个合数,其必用一个约数(除1外)小于等于其平方根(可用反证法证明),所以我们只需要判断2~之间的数即可.b

2015-02-20 21:25:07 6790

原创 Sparse Table讲解

Sparse Tabel名为稀疏表,又称为ST表,可以在O(1)的时间复杂度下完成查询区间最值,相比线段树和树状数组,效率提升了不少.ST表本质上是一个很经典的dp,通过预处理完成O(1)的查询.既然是个dp,那我们来看下dp的定义吧(下面以查询区间最大值为例).dp[i][j]:表示以i为起点,长度为2^j的区间最值那么我们很容易得出状态转移方程:

2015-02-03 11:37:18 1106

原创 LeetCode:Implement strStr()

Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null ifneedle is not part of haystack.解题思路:    strstr()函数隶属标准库string.h头文件,其内部的实现是O(n^2)的时间复

2014-07-16 21:34:01 1324

原创 POJ 3734

题目的大意:给定待粉刷的n个墙砖(排成一行),每个墙砖可以粉刷的颜色种类为:红、蓝、绿、黄,问粉刷完毕后,红色墙砖和蓝色墙砖都是偶数的粉刷方式有多少种(结果对10007取余).解题思路:思路用的是递推.假设粉刷到第i个墙砖时,使用的红色墙砖和蓝色墙砖都是偶数的方案数有ai,使用的红色和蓝色墙砖一奇一偶的方案数为bi,使用的红色和蓝色墙砖都

2014-07-14 22:56:41 1147

原创 LeetCode:Longest Valid Parentheses

Given a string containing just the characters '(' and ')', find thelength of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()

2014-06-30 23:54:54 1019

原创 LeetCode:Combinations

Given two integers n and k, return all possible combinations of k numbers out of 1 ...n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3

2014-06-25 19:40:09 922

原创 LeetCode:Length of Last Word

Given a string s consists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word does not exist, return 0.Note

2014-06-25 18:40:24 789

原创 LeetCode:Interleaving String

Given s1, s2,s3, find whether s3 is formed by the interleaving of s1 ands2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When

2014-06-25 14:14:07 864

原创 LeetCode:Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" i

2014-06-23 00:05:45 971

原创 LeetCode:Subsets II

Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplica

2014-06-22 19:44:40 1016

原创 LeetCode:Pascal's Triangle II

Given an index k, return thekth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use onlyO(k) extra space?

2014-06-20 16:25:26 763

原创 Pascal's Triangle

Given numRows, generate the firstnumRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]解题思路: 杨辉三角没什么好说的

2014-06-20 16:21:08 830

原创 LeetCode:Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you maymove to adjacent numbers on the row below.For example, given the following triangle[ [2],

2014-06-19 23:30:34 944

原创 LeetCode:Subsets

Given a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,

2014-06-17 17:52:47 1363

原创 LeetCode:Edit Distance

Given two words word1 and word2, find the minimum number of steps required to convertword1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted

2014-06-17 01:35:45 1210

原创 LeetCode:Merge Sorted Array

Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal tom + n) to hold additional ele

2014-06-16 20:41:23 721

原创 LeetCode:Sum Root to Leaf Numbers

Given a binary tree containing digits from0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3 which represents the number 123.F

2014-06-14 17:32:31 1052

原创 LeetCode:Path Sum II

Given a binary tree and a sum, find all root-to-leaf paths where each path'ssum equals the given sum.For example:Given the below binary tree andsum = 22, 5

2014-06-13 11:55:37 882

原创 LeetCode:Path Sum

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such thatadding up all the values along the path equals the given sum.For example:Given the below bin

2014-06-12 23:12:31 855

原创 LeetCode:Same Tree

Same Tree     Given two binary trees, write a function to check if they are equal or not.    Two binary trees are considered equal if they are structurally identical andthe n

2014-06-12 00:10:23 793

原创 LeetCode:Reorder List

Given a singly linked listL: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes' values. For example,Given {1,2,3,4}, r

2014-05-29 22:21:47 1019

原创 LeetCode:4Sum

Given an array S of n integers, are there elementsa, b, c, and d in S such that a +b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:

2014-05-27 16:45:41 884

原创 LeetCode:Add Two Numbers

You are given two linked lists representing two non-negative numbers. The digits are stored in  reverse order and each of their nodes contain a single digit. Add the two numbers and return i

2014-05-25 19:43:30 798

原创 LeetCode:3Sum Closest

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact

2014-05-24 00:51:59 1076 1

原创 LeetCode:3Sum

题目:       Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements

2014-05-22 19:01:23 748

原创 LeetCode:Two Sum

题目:      Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up t

2014-05-20 14:58:44 813

原创 LeetCode:Single Number II

题目:    Given an array of integers, every element appearsthree times except for one. Find that single one.    Note:    Your algorithm should have a linear runtime complexity. Could you implem

2014-05-19 23:14:25 1020

原创 POJ 3171

题目大意:       给定一个区间范围[M,E],接下来有n行输入,每行输入三个数值:T1,T2,S,表示覆盖区间[T1,T2]的代价为S,要求你求出覆盖区间[M,E]的最小代价,如果不能覆盖,则输出-1.解题思路:         先将区间按右端点进行排序,这样我们就能得到dp状态的定义和转移方程:                  dp[i

2014-05-19 00:29:57 1972

转载 拓扑排序

原文链接: dzone 翻译: ImportNew.com - 陈 秋林译文链接: http://www.importnew.com/9719.html介绍假设我们有一组任务要完成,并且有些任务要在其它任务完成之后才能开始,所以我们必须非常小心这些任务的执行顺序。如果这些任务的执行顺序足够简单的话,我们可以用链表来存储它们,这是一个很好的方案,让我们可以

2014-03-09 17:05:50 1062

原创 POJ 3667(线段树+lazy思想)

题目链接:http://poj.org/problem?id=3667题目的意思很简单,给定你一个数字N,表示有N个房间(编号为1到N),然后有M个询问操作:1. 1 x:查询操作,如果N个房间中,存在有x个连续的房间,那么,输出满足条件的最小房间起始标号,并分配这x个房间,如果不存在,则输出0.2. 2 x y:将[x,y]这段区间的房间置为空.这是典型的一道线段树的区间

2013-11-28 16:10:15 785

原创 有关C++中的流操纵算子

C++提供了大量的用于执行格式化输入/输出的流操纵算子。流操纵算子提供了许多功能,如设置域宽、设置精度、设置和清除格式化标志、设置域填充字符、刷新流、在输出流中插入换行符并刷新该流、在输出流中插入空字符、跳过输入流中的空白字符等等。下面几节要介绍这些特征。1.setbase(int _base):以进制基数b为输出整数值,支持将整数按照_base进制格式进行输出,使用setbase或者其他的任

2013-09-06 12:27:45 3130

转载 搜索引擎命令

本文转载自:http://www.zhihu.com/question/201613621、双引号把搜索词放在双引号中,代表完全匹配搜索,也就是说搜索结果返回的页面包含双引号中出现的所有的词,连顺序也必须完全匹配。bd和Google 都支持这个指令。例如搜索: “seo方法图片”2、减号减号代表搜索不包含减号后面的词的页面。使用这个指令时减号前面必须是空格,减号后面

2013-07-26 11:07:44 1501

原创 给定只包含正数的数组,给出一个方法,将数组中的数拼接起来,得到的数,是最大的。

题目:给定只包含正数的数组,给出一个方法,将数组中的数拼接起来,得到的数,是最大的。如果a[5]={10,110,1110,1,1},则所的最大数为11111011010.分析:这个问题初看是个排列组合的一个问题,我们可以将这个数组里面所有的数进行一个全排列,然后去找满足条件的那组数据,这样做,肯定是可以的,不过就是时间复杂度是阶乘级别的,不太可取。。不过,我们可以肯定的是,所

2013-07-21 12:33:00 2119

原创 迷宫问题

迷宫问题很经典,对于学习搜索很有帮助,特别是针对深搜,下面我们就来看关于迷宫中的一些常见的问题:从起点到终点的最小步数(前提是起点和终点是可达的)打印出起点到终点的所有通路。打印起点到终点的一条最短路径1.先来看第一个问题:从起点到终点的最小步数,迷宫中可能起点到终点存在很多的通路(我们找最小的步数,需要把所有的通路都搜遍,才能确定),而我们只用找最小的那条通路的步数就可以了(我们

2013-07-17 21:11:46 1441

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除