摘要: 题目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=63 思路: 从第一个牌堆开始,向右进行遍历。若存在左边第三个牌堆,则优先考虑能否移动到左边第三个牌堆 阅读全文
posted @ 2017-03-06 20:15 淡蓝色光 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 给定一个序列,下标为 i, i+1, i+2, ...... , j,设 mid = (i+j)/2, 则最大子序列可能出现的地方有三个,mid的左边,mid的右边,或者在中间(包括mid)。只要求出左边和右边的最大子序列(子问题),和边界上左边和右边最大子序列的和,找出三个子序列中最大的即可。 时 阅读全文
posted @ 2017-02-18 11:18 淡蓝色光 阅读(516) 评论(0) 推荐(0) 编辑
摘要: 掌握链表的删除,插入,遍历。可以用数组来构造链表。 例题 6-4 题目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=838&page=show_problem&problem=3139 阅读全文
posted @ 2016-11-30 17:57 淡蓝色光 阅读(181) 评论(0) 推荐(0) 编辑
摘要: //快期末了,挺忙的,打算把第六章的内容从新再复习一遍了,很多细节的地方还没掌握。 栈: 满足后进先出,C++中可以用 STL 中的 stack 来构造。 构造方法为:stack<数据类型> 栈名字。top() 取栈顶元素,pop() 栈顶出栈,push(元素) 将元素压入栈。 队列: 满足先进先出 阅读全文
posted @ 2016-11-22 20:33 淡蓝色光 阅读(1101) 评论(0) 推荐(1) 编辑
摘要: 题目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=839&page=show_problem&problem=653 思路:当前结点为k,左走则 2k,右走则 2k + 1,得到最后的点 阅读全文
posted @ 2016-11-10 23:09 淡蓝色光 阅读(602) 评论(0) 推荐(0) 编辑
摘要: 题目: 思路: 方法很巧妙,参考的网上的方法。 任意一点都可以决定整棵树(根结点)的重量,设这个结点重量为 w ,位于第 depth 层,则整棵树的重量为 w<<depth。因此只要统计所有点对应的整棵树的重量所出现的次数,再用点的数量减去重量出现最多的次数即为答案。 阅读全文
posted @ 2016-11-09 19:59 淡蓝色光 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 题目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=839&page=show_problem&problem=4475 思路:用 BFS 求解。 注意:BFS 中的每一个结点应该为 (行 阅读全文
posted @ 2016-11-07 20:43 淡蓝色光 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 题目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=839&page=show_problem&problem=380 思路:用 BFS 求出到终点的最短距离即可。 小技巧:用一个 dir 阅读全文
posted @ 2016-11-06 11:24 淡蓝色光 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 题目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=839&page=show_problem&problem=477 思路:根据先序遍历和中序遍历建树,再输出下后序遍历即可 阅读全文
posted @ 2016-11-03 21:46 淡蓝色光 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 题目:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=839&page=show_problem&problem=614 思路:直接用栈解决即可 若当前字符和栈顶的字符配对时( “()” 或 阅读全文
posted @ 2016-11-03 21:42 淡蓝色光 阅读(225) 评论(0) 推荐(0) 编辑