- 博客(21)
- 收藏
- 关注
原创 关于“simplicity”的看法 -- 读《Masterminds of Programming》有感
任何编程语言,都是解决实际问题的工具。我想,没有那个语言的创始人只希望他的语言是同行的热点话题,却很少有程序员去使用它。所以我想,从解决实际问题的角度出发,去看待语言的“简单”,我们能得到很多启示。那么我对“简单”的看法是什么呢?我一一列举:1、简单不是一个独立概念,它必然是相对复杂而言的。当我们定义了简单,我们也就定义了复杂。反过来也如此,定义了复杂也就定义了简单;2、《Co
2016-01-24 12:11:18
540
原创 Presorting
Exercises 6.11def min_diff(L): n = len(L) if n > 1: L = sorted(L) md = L[1] - L[0] i = 2 while i < n: d = L[i] - L[i - 1] if
2016-01-12 20:25:09
622
原创 The Maximum-Subarray Problem
Suppose that you have been offered the opportunity to invest in the Volatile Chemical Corporation. Like the chemicals the company produces, the stock price of the Volatile Chemical Corporation is rath
2015-12-27 23:18:09
767
原创 Use python to implement Dijkstra's algorithm
The implementation of the Dijkstra's Algorithm:def dijkstra(g, s): from priority_queue import PriorityQueue, less_than result = [] class Record: def __init__(self, v, parent = -
2015-12-25 20:56:40
385
原创 Two ways to solve the "Longest common subsequence" problem
namespace v1 { template std::basic_string lcs(const CHAR * s1, const CHAR * s2) { typedef std::basic_string String; String ret; int m =
2015-02-27 16:53:26
439
原创 Implement most-significant-digit-first string sort
namespace pratique{ namespace details { const size_t CUTOFF = 15; int compare(const char * s1, const char * s2, size_t d) { int ret = 0; s1 +=
2015-01-20 16:37:21
607
原创 How to implement segment tree
template class segment_tree { struct record { int left; int right; T value; T sum; }; int m_siz
2015-01-18 17:53:53
476
原创 Three ways to solve the "Longest Palindromic Substring" problem
namespace v1 { namespace details { inline bool is_palindromic(int i, int j, std::vector>> & cache) { std::pair deux = cache[i][j];
2015-01-11 00:12:05
470
原创 How to solve the Candy problem?
The problem is:There are N children 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 mu
2015-01-09 15:34:04
479
原创 Give an O(log m + log n) algorithm to find the kth element in two sorted arrays
Give an O(log (m+n)) algorithm to find the kth element in two sorted arrays A and B of size m and n respectively as if they are merged.namespace details{ template I kth_element( I b1, I
2015-01-09 01:59:10
546
原创 Use Python to implement Trie
class TrieKeyIterator: def __init__(self, root): self.root = root self.root_list = {'' : self.root} self.stack = [(iter(self.root_list.items()), '')] def __next__(self
2014-11-03 22:01:23
640
原创 What is the probability that you hire exactly twice?
In HIRE-ASSISTANT, assuming that the candidates are presented in a random order,
2014-09-01 14:30:39
3453
原创 Efficiently factor N when e and d become known to you.
The problem is:In the RSA cryptosystem, Alice’s public key (N, e) is available to everyone. Suppose that her private key d is compromised and becomes known to Eve. Show that if e = 3 (a common choic
2014-08-24 10:26:26
1599
原创 Implement regular expressions
namespace details { void dfs_visit( size_t u, std::vector> & g, std::vector & visited ) { visited[ u ] = true; for ( auto i = g[ u ].begin(), e = g[ u ] .en
2014-06-08 21:42:47
708
原创 Recursion problems
Problem : print out all of the permutations of n elements:
2014-05-03 09:08:57
492
原创 Implement the avl tree, rbtree without the two fields: parent pointer and balance/color
#ifndef GYM_RED_BLACK_TREE_H_6D4EBDB0_5B18_4FC1_A34A_CBBF36FE95E4#define GYM_RED_BLACK_TREE_H_6D4EBDB0_5B18_4FC1_A34A_CBBF36FE95E4#include #include #include #include #include #include #includ
2014-02-13 16:54:49
727
原创 Give an O(lg n)-time algorithm to find the median of all 2n elements in arrays X and Y.
Let X[1 ‥ n] and Y[1 ‥ n] be two arrays, each containing n numbers already in sorted order. Give anO(lg n)-time algorithm to find the median of all 2n elements in arraysX and Y. template
2013-08-27 16:08:05
1340
原创 Implement the quicksort algorithm in as many different ways as possible
#ifndef GYM_ALGORITHM_QUICK_SORT_H_6D4EBDB0_5B18_4FC1_A34A_CBBF36FE95E4#define GYM_ALGORITHM_QUICK_SORT_H_6D4EBDB0_5B18_4FC1_A34A_CBBF36FE95E4#include #include "sort_common.h"#include "inser
2012-10-31 11:10:16
617
原创 If only one side of processes crash, the other side of processes do not hang.
Use the shared memory to implement a queue, and producers can use it to transfer data to consumers. If only one side of processes crash, the other side of processes do not hang. The interface is:
2012-08-27 16:19:14
646
原创 Reverse a doubly linked list in O(1) time
#ifndef GYM_CLRS_V3_10_2_8_LINKED_LIST_H_6D4EBDB0_5B18_4FC1_A34A_CBBF36FE95E4#define GYM_CLRS_V3_10_2_8_LINKED_LIST_H_6D4EBDB0_5B18_4FC1_A34A_CBBF36FE95E4#include #include #include names
2012-08-12 20:30:19
1250
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人