随笔- 509  文章- 0  评论- 151  阅读- 22万 
02 2014 档案
LeetCode - Sudoku Solver
摘要:Sudoku Solver2014.2.28 21:30Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character'.'.You may assume that there will be only one unique solution.A sudoku puzzle......and its solution numbers marked in red.Solution: My solution to this p 阅读全文
posted @ 2014-02-28 21:54 zhuli19901106 阅读(465) 评论(0) 推荐(0) 编辑
LeetCode - Implement strStr()
摘要:Implement strStr()2014.2.28 02:38Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.Solution1: The first one is brute-force, reference is from source code of strstr() in . Total time complexity is O(n * m). Space complexity i.. 阅读全文
posted @ 2014-02-28 02:42 zhuli19901106 阅读(259) 评论(0) 推荐(0) 编辑
LeetCode - Wildcard Matching
摘要:Wildcard Matching2014.2.28 01:49Implement wildcard pattern matching with support for'?'and'*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The fun 阅读全文
posted @ 2014-02-28 02:06 zhuli19901106 阅读(810) 评论(0) 推荐(0) 编辑
LeetCode - Word Ladder II
摘要:Word Ladder II2014.2.13 01:23Given two words (startandend), and a dictionary, find all shortest transformation sequence(s) fromstarttoend, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor example,Given:start="hit"end="cog"di 阅读全文
posted @ 2014-02-27 03:22 zhuli19901106 阅读(413) 评论(0) 推荐(0) 编辑
LeetCode - Word Ladder
摘要:Word Ladder2014.2.27 02:14Given two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor example,Given:start="hit"end="cog&quo 阅读全文
posted @ 2014-02-27 02:45 zhuli19901106 阅读(464) 评论(0) 推荐(0) 编辑
LeetCode - Word Break II
摘要:Word Break II2014.2.27 02:03Given a stringsand a dictionary of wordsdict, add spaces insto construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens="catsanddog",dict=["cat", "cats", "and", "san 阅读全文
posted @ 2014-02-27 02:12 zhuli19901106 阅读(470) 评论(0) 推荐(0) 编辑
LeetCode - Word Break
摘要:Word Break2014.2.27 01:46Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For example, givens="leetcode",dict=["leet", "code"].Return true because"leetcode"can be segmen 阅读全文
posted @ 2014-02-27 01:51 zhuli19901106 阅读(203) 评论(0) 推荐(0) 编辑
LeetCode - Valid Number
摘要:Valid Number2014.2.27 01:36Validate if a given string is numeric.Some examples:"0"=>true" 0.1 "=>true"abc"=>false"1 a"=>false"2e10"=>trueNote:It is intended for the problem statement to be ambiguous. You should gather all requirements 阅读全文
posted @ 2014-02-27 01:43 zhuli19901106 阅读(235) 评论(0) 推荐(0) 编辑
LeetCode - Surrounded Regions
摘要:Surrounded Regions2014.2.27 00:59Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region.For example,X X X XX O O XX X O XX O X XAfter running your function, the boa 阅读全文
posted @ 2014-02-27 01:27 zhuli19901106 阅读(413) 评论(0) 推荐(0) 编辑
LeetCode - Substring with Concatenation of All Words
摘要:Substring with Concatenation of All Words2014.2.27 00:46You are given a string,S, and a list of words,L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any intervening characters.For example, given:S: 阅读全文
posted @ 2014-02-27 00:57 zhuli19901106 阅读(256) 评论(0) 推荐(0) 编辑
LeetCode - Scramble String
摘要:Scramble String2014.2.27 00:04Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation ofs1="great": great / \ gr eat / \ / \g r e at / \ a tTo scramble the string,... 阅读全文
posted @ 2014-02-27 00:15 zhuli19901106 阅读(362) 评论(0) 推荐(0) 编辑
LeetCode - Word Search
摘要:Word Search2014.2.26 23:59Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.Fo 阅读全文
posted @ 2014-02-27 00:03 zhuli19901106 阅读(1223) 评论(0) 推荐(0) 编辑
LeetCode - Reverse Nodes in k-Group
摘要:Reverse Nodes in k-Group2014.2.26 23:37Given a linked list, reverse the nodes of a linked listkat a time and return its modified list.If the number of nodes is not a multiple ofkthen left-out nodes in the end should remain as it is.You may not alter the values in the nodes, only nodes itself may be 阅读全文
posted @ 2014-02-26 23:55 zhuli19901106 阅读(192) 评论(0) 推荐(0) 编辑
LeetCode - Palindrome Partitioning II
摘要:Palindrome Partitioning II2014.2.26 22:57Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs.For example, givens="aab",Return1since the palindrome partitioning["aa","b"]co 阅读全文
posted @ 2014-02-26 23:22 zhuli19901106 阅读(213) 评论(0) 推荐(0) 编辑
LeetCode - Palindrome Partitioning
摘要:Palindrome Partitioning2014.2.26 22:36Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, givens="aab",Return [ ["aa","b"], ["a","a","b"] ]Soluti 阅读全文
posted @ 2014-02-26 22:51 zhuli19901106 阅读(294) 评论(0) 推荐(0) 编辑
LeetCode - Merge Interval.
摘要:Merge Intervals2014.2.26 21:28Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].Solution: The problem didn't guarantee that the set of intervals is sorted, so a sort() has to be performed first. After sorting t 阅读全文
posted @ 2014-02-26 21:43 zhuli19901106 阅读(530) 评论(0) 推荐(0) 编辑
LeetCode - Minimum Window Substring
摘要:Minimum Window Substring2014.2.26 21:17Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S="ADOBECODEBANC"T="ABC"Minimum window is"BANC".Note:If there is no such window in S that cover 阅读全文
posted @ 2014-02-26 21:26 zhuli19901106 阅读(244) 评论(0) 推荐(0) 编辑
LeetCode - Maximal Rectangle
摘要:Maximal Rectangle2014.2.26 20:27Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.Solution: The worst solution for this problem should be O(n^4), and you will use O(n^2) space to speed it up to O(n^3). But we're discussin 阅读全文
posted @ 2014-02-26 20:51 zhuli19901106 阅读(459) 评论(0) 推荐(0) 编辑
LeetCode - Max Points on a Line
摘要:Max Points on a Line2014.2.26 18:13Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.Solution1: A simple solution to this problem is O(n^3). Scan every pair of points and see if others are on the line with them. Simple but not efficient. The second so.. 阅读全文
posted @ 2014-02-26 18:48 zhuli19901106 阅读(401) 评论(0) 推荐(0) 编辑
LeetCode - Largest Rectangle in Histogram
摘要:Largest Rectangle in Histogram2014.2.26 05:06Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each bar is 1, given height =[2,1,5,6,2,3].The largest rectan 阅读全文
posted @ 2014-02-26 05:22 zhuli19901106 阅读(283) 评论(0) 推荐(0) 编辑
LeetCode - Jump Game II
摘要:Jump Game II2014.2.26 04:35Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to reach the last index in the minimum number of jumps.For example:Given array 阅读全文
posted @ 2014-02-26 04:45 zhuli19901106 阅读(211) 评论(0) 推荐(0) 编辑
LeetCode - Jump Game
摘要:Jump Game2014.2.26 04:21Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you are able to reach the last index.For example:A =[2,3,1,1,4], returntrue.A =[3, 阅读全文
posted @ 2014-02-26 04:29 zhuli19901106 阅读(329) 评论(0) 推荐(0) 编辑
LeetCode - Interleaving String
摘要:Interleaving String2014.2.26 02:48Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="aadbbbaccc", return false.Solution1: This problem can be solved with DFS, bu 阅读全文
posted @ 2014-02-26 03:29 zhuli19901106 阅读(204) 评论(0) 推荐(0) 编辑
LeetCode - Gas Station
摘要:Gas Station2014.2.26 00:34There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited ... 阅读全文
posted @ 2014-02-26 02:09 zhuli19901106 阅读(351) 评论(0) 推荐(0) 编辑
LeetCode - Evaluate Reverse Polish Notation
摘要:Evaluate Reverse Polish Notation2014.2.25 23:42Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*"] -> (( 阅读全文
posted @ 2014-02-25 23:53 zhuli19901106 阅读(188) 评论(0) 推荐(0) 编辑
LeetCode - Edit Distance
摘要:Edit Distance2014.2.25 23:07Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) Insert a characterb) Delete a characterc) Replace a characterSolution1: This i. 阅读全文
posted @ 2014-02-25 23:39 zhuli19901106 阅读(186) 评论(0) 推荐(0) 编辑
LeetCode - Clone Graph
摘要:Clone Graph2014.2.25 22:15Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use#as a separator for each node, and,as a separator for node label and each neighbor of the node.As an example, 阅读全文
posted @ 2014-02-25 22:58 zhuli19901106 阅读(270) 评论(0) 推荐(0) 编辑
LeetCode - Candy
摘要:Candy2014.2.25 21:34There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one candy.Children with a higher rating get more candies than their neighbors.What is the mi 阅读全文
posted @ 2014-02-25 22:11 zhuli19901106 阅读(201) 评论(0) 推荐(0) 编辑
LeetCode - 3Sum Closest
摘要:3Sum Closest2014.2.25 19:02Given an arraySofnintegers, find three integers inSsuch 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 exactly one solution. For example, given array S = {-1 2 1 -4}, and target = 1. ... 阅读全文
posted @ 2014-02-25 21:16 zhuli19901106 阅读(286) 评论(2) 推荐(0) 编辑
LeetCode - Set Matrix Zeroes
摘要:Set Matrix Zeroes2014.2.13 22:15Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O(m+n) space, but still no 阅读全文
posted @ 2014-02-13 22:50 zhuli19901106 阅读(218) 评论(0) 推荐(0) 编辑
LeetCode - Search for a Range
摘要:Search for a Range2014.2.13 20:27Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order ofO(logn).If the target is not found in the array, return[-1, -1].For example,Given[5, 7, 7, 8, 8, 10]and targ 阅读全文
posted @ 2014-02-13 20:42 zhuli19901106 阅读(168) 评论(0) 推荐(0) 编辑
LeetCode - N-Queens II
摘要:N-Queens II2014.2.13 20:01Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.Solution: This problem is a simplification from the N-Queens. This time we only have record the number of solutions. Time complexity is O(n!). Space .. 阅读全文
posted @ 2014-02-13 20:22 zhuli19901106 阅读(294) 评论(0) 推荐(0) 编辑
LeetCode - N-Queens
摘要:N-Queens2014.2.13 19:23Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all distinct solutions to then-queens puzzle.Each solution contains a distinct board configuration of then-queens' placement, whe 阅读全文
posted @ 2014-02-13 19:45 zhuli19901106 阅读(344) 评论(0) 推荐(0) 编辑
LeetCode - LRU Cache
摘要:LRU Cache2014.2.13 18:15Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value)- Set or insert the 阅读全文
posted @ 2014-02-13 19:20 zhuli19901106 阅读(226) 评论(0) 推荐(0) 编辑
LeetCode - Longest Valid Parentheses
摘要:Longest Valid Parentheses2014.2.13 02:32Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest valid parentheses substring is"()", which has length = 2.Another example 阅读全文
posted @ 2014-02-13 02:43 zhuli19901106 阅读(230) 评论(0) 推荐(0) 编辑
LeetCode - Insert Interval
摘要:Insert Interval2014.2.13 01:23Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Example 1:Given intervals[1,3],[6,9], insert and merge[2,5]in as[1,5],[6,9].Examp 阅读全文
posted @ 2014-02-13 02:27 zhuli19901106 阅读(232) 评论(0) 推荐(0) 编辑
LeetCode - Flatten Binary Tree to Linked List
摘要:Flatten Binary Tree to Linked List2014.2.13 01:03Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 ... 阅读全文
posted @ 2014-02-13 01:22 zhuli19901106 阅读(189) 评论(0) 推荐(0) 编辑
LeetCode - Convert Sorted List to Binary Search Tree
摘要:Convert Sorted List to Binary Search Tree2014.2.13 00:46Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Solution: You may already have solved the problem Convert Sorted Array to Binary Search Tree, which can be done in O(n) time. Since l.. 阅读全文
posted @ 2014-02-13 01:00 zhuli19901106 阅读(192) 评论(0) 推荐(0) 编辑
LeetCode - Binary Tree Maximum Path Sum
摘要:Binary Tree Maximum Path Sum2014.2.12 23:49Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return6.Solution: The maximum path sum of a tree is a path from two nodes in the tree, that... 阅读全文
posted @ 2014-02-13 00:42 zhuli19901106 阅读(475) 评论(2) 推荐(0) 编辑
LeetCode - Trapping Rain Water
摘要:Trapping Rain Water2014.2.10 03:25Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example,Given[0,1,0,2,1,0,1,3,2,1,2,1], return6.The above elevation map is represented by array [0,1,0,2,1,0,1,3,2 阅读全文
posted @ 2014-02-10 03:38 zhuli19901106 阅读(270) 评论(0) 推荐(0) 编辑
LeetCode - Unique Binary Search Trees II
摘要:Unique Binary Search Trees II2014.2.10 02:54Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 unique BST's shown below. 1 3 3 2 1 \ / / / \ \ 3 2 ... 阅读全文
posted @ 2014-02-10 03:16 zhuli19901106 阅读(163) 评论(0) 推荐(0) 编辑
LeetCode - Text Justification
摘要:Text Justification2014.2.10 02:42Given an array of words and a lengthL, format the text such that each line has exactlyLcharacters and is fully (left and right) justified.You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces' ' 阅读全文
posted @ 2014-02-10 02:51 zhuli19901106 阅读(359) 评论(0) 推荐(0) 编辑
LeetCode - String to Integer (atoi)
摘要:String to Integer (atoi)2014.2.10 02:23Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.Notes:It is intended for this problem to be specified vaguely (i 阅读全文
posted @ 2014-02-10 02:37 zhuli19901106 阅读(196) 评论(0) 推荐(0) 编辑
LeetCode - Longest Palindromic Substring
摘要:Longest Palindromic Substring2014.2.10 00:57Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest palindromic substring.Solution1: My first solution to this problem is the brute-force version, with O(n^2) . 阅读全文
posted @ 2014-02-10 01:36 zhuli19901106 阅读(317) 评论(0) 推荐(0) 编辑
LeetCode - Permutation Sequence
摘要:Permutation Sequence2014.2.9 01:00The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, forn= 3):"123""132""213""231""312""321"Givennandk, ret 阅读全文
posted @ 2014-02-09 01:17 zhuli19901106 阅读(230) 评论(0) 推荐(0) 编辑
LeetCode - First Missing Positive
摘要:First Missing Positive2014.2.8 23:43Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should run inO(n) time and uses constant space.Solution1: The first solution I thought of was hashing, using unordered_map. 阅读全文
posted @ 2014-02-08 23:58 zhuli19901106 阅读(168) 评论(0) 推荐(0) 编辑
LeetCode - Distinct Subsequences
摘要:Distinct Subsequences2014.2.8 22:11Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remai 阅读全文
posted @ 2014-02-08 22:16 zhuli19901106 阅读(177) 评论(0) 推荐(0) 编辑
LeetCode - Container With Most Water
摘要:Container With Most Water2014.2.8 21:37Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the conta 阅读全文
posted @ 2014-02-08 22:08 zhuli19901106 阅读(140) 评论(0) 推荐(0) 编辑
LeetCode - 4Sum
摘要:4Sum2014.2.8 20:58Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie,a≤b≤c≤d)The solution set must not contain duplic 阅读全文
posted @ 2014-02-08 21:15 zhuli19901106 阅读(205) 评论(0) 推荐(0) 编辑
剑指Offer - 九度1524 - 复杂链表的复制
摘要:剑指Offer - 九度1524 - 复杂链表的复制2014-02-07 01:30题目描述:输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点)。输入:输入可能包含多个测试样例,输入以EOF结束。对于每个测试案例,输入的第一行为一个整数n (1 4 #include 5 using namespace std; 6 7 struct RandomListNode { 8 int label; 9 RandomListNode *next, *random; 10 RandomListNode(int ... 阅读全文
posted @ 2014-02-07 01:44 zhuli19901106 阅读(437) 评论(0) 推荐(0) 编辑
剑指Offer - 九度1509 - 树中两个结点的最低公共祖先
摘要:剑指Offer - 九度1509 - 树中两个结点的最低公共祖先2014-02-07 01:04题目描述:给定一棵树,同时给出树中的两个结点,求它们的最低公共祖先。输入:输入可能包含多个测试样例。对于每个测试案例,输入的第一行为一个数n(0 7 #include 8 using namespace std; 9 10 const int MAXN = 10005; 11 // tree[x][0]: parent of node x 12 // tree[x][1]: left child of node x 13 // tree[x][2]: right child of node... 阅读全文
posted @ 2014-02-07 01:20 zhuli19901106 阅读(526) 评论(0) 推荐(0) 编辑
剑指Offer - 九度1508 - 把字符串转换成整数
摘要:剑指Offer - 九度1508 - 把字符串转换成整数2014-02-06 23:46题目描述:将一个字符串转换成一个整数,要求不能使用字符串转换整数的库函数。输入:输入可能包含多个测试样例。对于每个测试案例,输入为一个合法或者非法的字符串,代表一个整数n(1 4 #include 5 #include 6 using namespace std; 7 8 int main() 9 {10 int i;11 char s[100];12 int len;13 long long int n;14 int flag;15 bool suc;... 阅读全文
posted @ 2014-02-07 00:25 zhuli19901106 阅读(375) 评论(0) 推荐(0) 编辑
剑指Offer - 九度1504 - 把数组排成最小的数
摘要:剑指Offer - 九度1504 - 把数组排成最小的数2014-02-06 00:19题目描述:输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323。输入:输入可能包含多个测试样例。对于每个测试案例,输入的第一行为一个整数m (1 4 #include 5 #include 6 #include 7 using namespace std; 8 9 vector vv;10 int n;11 12 bool comparator(const string &x, 阅读全文
posted @ 2014-02-06 00:28 zhuli19901106 阅读(343) 评论(0) 推荐(0) 编辑
剑指Offer - 九度1503 - 二叉搜索树与双向链表
摘要:剑指Offer - 九度1503 - 二叉搜索树与双向链表2014-02-05 23:39题目描述:输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。输入:输入可能包含多个测试样例。对于每个测试案例,输入的第一行为一个数n(0 5 #include 6 #include 7 using namespace std; 8 9 typedef struct st{ 10 public: 11 int key; 12 struct st *ll; 13 struct st *rr; 14 ... 阅读全文
posted @ 2014-02-06 00:09 zhuli19901106 阅读(275) 评论(0) 推荐(0) 编辑
剑指Offer - 九度1390 - 矩形覆盖
摘要:剑指Offer - 九度1390 - 矩形覆盖2014-02-05 23:27题目描述:我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?输入:输入可能包含多个测试样例,对于每个测试案例,输入包括一个整数n(1 4 #include 5 using namespace std; 6 7 int main() 8 { 9 const int MAXN = 71;10 long long int res[MAXN];11 12 res[0] = res[1] = 1;13 int i;... 阅读全文
posted @ 2014-02-05 23:33 zhuli19901106 阅读(271) 评论(0) 推荐(0) 编辑
剑指Offer - 九度1373 - 整数中1出现的次数(从1到n整数中1出现的次数)
摘要:剑指Offer - 九度1373 - 整数中1出现的次数(从1到n整数中1出现的次数)2014-02-05 23:03题目描述:亲们!!我们的外国友人YZ这几天总是睡不好,初中奥数里有一个题目一直困扰着他,特此他向JOBDU发来求助信,希望亲们能帮帮他。问题是:求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1、10、11、12、13因此共出现6次,但是对于后面问题他就没辙了。ACMer希望你们帮帮他,并把问题更加普遍化,可以很快的求出任意非负整数区间中1出现的次数。输入:输入有多组数据,每组测试数据为一行。每一行有两个整 阅读全文
posted @ 2014-02-05 23:25 zhuli19901106 阅读(330) 评论(0) 推荐(0) 编辑
剑指Offer - 九度1369 - 字符串的排列
摘要:剑指Offer - 九度1369 - 字符串的排列2014-02-05 21:12题目描述:输入一个字符串,按字典序打印出该字符串中字符的所有排列。例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba。输入:每个测试案例包括1行。输入一个字符串,长度不超过9(可能有字符重复),字符只包括大小写字母。输出:对应每组数据,按字典序输出所有排列。样例输入:abcBCA样例输出:abcacbbacbcacabcbaABCACBBACBCACABCBA题意分析: 给定一个字符串,输出有其中的字母所能构成的全部排列。 首先,STL的alg.. 阅读全文
posted @ 2014-02-05 21:22 zhuli19901106 阅读(340) 评论(0) 推荐(0) 编辑
剑指Offer - 九度1366 - 栈的压入、弹出序列
摘要:剑指Offer - 九度1366 - 栈的压入、弹出序列2014-02-05 20:41题目描述:输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个弹出序列,但4,3,5,1,2就不可能是该压栈序列的弹出序列。输入:每个测试案例包括3行:第一行为1个整数n(1 4 #include 5 #include 6 using namespace std; 7 8 map m2; 9 stack st;10 const int MAXN = 10... 阅读全文
posted @ 2014-02-05 20:47 zhuli19901106 阅读(246) 评论(0) 推荐(0) 编辑
剑指Offer - 九度1360 - 乐透之猜数游戏
摘要:剑指Offer - 九度1360 - 乐透之猜数游戏2014-02-05 19:54题目描述:六一儿童节到了,YZ买了很多丰厚的礼品,准备奖励给JOBDU里辛劳的员工。为了增添一点趣味性,他还准备了一些不同类型的骰子,打算以掷骰子猜数字的方式发放奖品。例如,有的骰子有6个点数(点数分别为1~6),有的骰子有7个(点数分别为1~7),还有一些是8个点数(点数分别为1~8)。他每次从中拿出n个同一类型的骰子(假设它们都是拥有m个点数并且出现概率相同)投掷,然后让员工在纸上按优先级(从高到低)的顺序写下3个数上交,表示他们认为这些骰子最有可能的点数之和是多少。第一个数就猜对的人,是一等奖;第二个数才 阅读全文
posted @ 2014-02-05 20:35 zhuli19901106 阅读(376) 评论(0) 推荐(0) 编辑
剑指Offer - 九度1356 - 孩子们的游戏(圆圈中最后剩下的数)
摘要:剑指Offer - 九度1356 - 孩子们的游戏(圆圈中最后剩下的数)2014-02-05 19:37题目描述:每年六一儿童节,JOBDU都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此。HF作为JOBDU的资深元老,自然也准备了一些小游戏。其中,有个游戏是这样的:首先,让小朋友们围成一个大圈。然后,他随机指定一个数m,让编号为1的小朋友开始报数。每次喊到m的那个小朋友要出列唱首歌,然后可以在礼品箱中任意的挑选礼物,并且不再回到圈中,从他的下一个小朋友开始,继续1...m报数....这样下去....直到剩下最后一个小朋友,可以不用表演,并且拿到JOBDU名贵的“名侦探柯南”典藏版(名额有 阅读全文
posted @ 2014-02-05 19:41 zhuli19901106 阅读(885) 评论(0) 推荐(0) 编辑
剑指Offer - 九度1355 - 扑克牌顺子
摘要:剑指Offer - 九度1355 - 扑克牌顺子2014-01-30 23:19题目描述:LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张^_^)...他随机从中抽出了5张牌,想测测自己的手气,看看能不能抽到顺子,如果抽到的话,他决定去买体育彩票,嘿嘿!!“红心A,黑桃3,小王,大王,方片5”,“Oh My God!”不是顺子.....LL不高兴了,他想了想,决定大\小王可以看成任何数字,并且A看作1,J为11,Q为12,K为13。上面的5张牌就可以变成“1,2,3,4,5”(大小王分别看作2和4),“So Lucky!”。LL决定去买体育彩票啦 阅读全文
posted @ 2014-02-05 18:35 zhuli19901106 阅读(412) 评论(0) 推荐(0) 编辑
剑指Offer - 九度1352 - 和为S的两个数字
摘要:剑指Offer - 九度1352 - 和为S的两个数字2014-02-05 18:15题目描述:输入一个递增排序的数组和一个数字S,在数组中查找两个数,是的他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的。输入:每个测试案例包括两行:第一行包含一个整数n和k,n表示数组中的元素个数,k表示两数之和。其中1 4 using namespace std; 5 6 const int MAXN = 1000005; 7 int a[MAXN]; 8 int n; 9 int k;10 11 int main()12 {13 int i;14 bool suc;1... 阅读全文
posted @ 2014-02-05 18:20 zhuli19901106 阅读(422) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示