
算法
SUN_DRAGON
这个作者很懒,什么都没留下…
展开
-
Nim游戏
http://www.cnblogs.com/exponent/articles/2141477.html http://blog.youkuaiyun.com/swordholy/article/details/4852753 http://wenku.baidu.com/view/8cc03974a417866fb84a8eeb.html http://wenku.baidu.com/view/e9原创 2013-03-11 09:58:50 · 922 阅读 · 0 评论 -
pku 1704 Georgia and Bob
题意:给一个1*M的棋盘,上面有N颗棋子,每次只能向左移动棋子,并且至少移动一步,两人轮流操作,谁不能移动谁就输了。 分析这题的P/N点时,和往常不一样,不是从小数据推测,而是直接从性质推测,从右往左,把棋子分为两两一组,如果是奇数颗棋子,就补第一颗的位置为0,当对手移动两颗棋子的左边的棋子时,我们只需要把右边这颗棋子移动相同的步数就行,当对手移动右边的棋子时,把两颗棋子之间的距离看转载 2013-03-11 10:41:40 · 827 阅读 · 0 评论 -
sg函数和nim问题
“Sprague-Grundy函数” 我们将面对更多与Nim游戏有关的变种,还会看到Nim游戏的a1^a2^...^an这个值更广泛的意义。 上面的文章里我们仔细研究了Nim游戏,并且了解了找出必胜策略的方法。但如果把Nim的规则略加改变,你还能很快找出必胜策略吗?比如说:有n堆石子,每次可以从第1堆石子里取1颗、2颗或3颗,可以从第2堆石子里取奇数颗,可以从第3堆及以后石子里取任意颗……转载 2013-03-11 17:29:47 · 2185 阅读 · 1 评论 -
Palindrome partitioning
Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","b"], ["a","a","原创 2013-03-14 16:02:51 · 1529 阅读 · 0 评论 -
时间o(n)空间o(1) 奇在前偶在后
#define EXCHANGE(a, b) (a)=(a)^(b);\ (b)=(b)^(a);\ (a)=(b)^(a) void oddEvenNum(vector& nums) { int oddEnd = 0; int evenEnd = 0; while(evenEnd < nums.size()) { if(nums[evenEnd] % 2) { if(原创 2013-03-18 10:22:17 · 690 阅读 · 0 评论 -
sum root to leafs nums
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the to原创 2013-03-18 09:22:29 · 745 阅读 · 0 评论 -
longest consecutive elements sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [1, 2, 3,原创 2013-03-21 12:10:20 · 993 阅读 · 0 评论 -
word ladder
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that: Only one letter can be changed at a timeEach intermediate word原创 2013-03-23 22:29:45 · 903 阅读 · 0 评论