Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum =...
分类:
其他好文 时间:
2014-07-02 22:10:42
阅读次数:
262
Given 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 ...
分类:
其他好文 时间:
2014-07-02 21:13:05
阅读次数:
170
#define FIND(struc,e) (int)&(((struc *)0)->e)...
分类:
编程语言 时间:
2014-07-02 08:13:52
阅读次数:
257
题目链接:Find a Way
题目不难,前几天做,当时准备写双向BFS的,后来处理细节上出了点问题,赶上点事搁置了,今天晚上重写的,没用双向,用了两次BFS搜索,和双向BFS 道理差不多,只是这题有个小坑,需要注意
1.Y不能经过M,M不能经过Y,也就是说有Y和M的格子,可以默认为是墙
2.必须是Y和M都能到达的KFC才行,只是其中一个到达不行
例如下列数据;答案既不是22 也不...
分类:
其他好文 时间:
2014-07-02 08:13:15
阅读次数:
197
【题目】
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
【题意】
给定一堆点,要求找出一条之前上的最大点数
【思路】
没什么好的方法,从每个点P出发,遍历所有的情况
从每个点P出发,斜率相同的点即为统一之前上的点
注意两种特殊情况:
1. 两个点重合(即为同一个点)
...
分类:
其他好文 时间:
2014-07-02 06:52:06
阅读次数:
171
find的语法:find [起始目录] 寻找条件 操作find ./msg -name "*.h" -o -name "*.hpp"在当前msg目录下查找以.h或.hpp结尾的文件,这两个 -name 之间的 -o 表示逻辑或(or)
分类:
系统相关 时间:
2014-07-01 17:59:32
阅读次数:
215
Union Find就是所谓的并查集。
本题做的很无语,最后发现居然是输入搞错,一直WA。
不能使用循环接受输入,否则是WA的,气死人,浪费那么多时间就为了这个。
难点:
1 构建关系树
2 构建公式
3 快速更新公式
要抽象思维出什么对应什么的关系和上面是逆关系,就是利用0,1,2构建出父子节点之间的关系值,我是这样去思考构建出准确无误的公式的。
这样的抽象度是挺高的,需要多多训...
分类:
其他好文 时间:
2014-07-01 11:15:20
阅读次数:
190
题目:
链接:点击打开链接
题意:
思路:
冲突的条件是:两个人坐在同一行,同时他们到根节点的差值等于他们之间的差值,这时就产生冲突了。于是我们可以用一个dist数组来保存节点到根的距离,而这个距离在路径压缩的时候更新一下就可以了,dist[x]+=dist[parent[x]]。然后就是合并后的距离,令r1=Find(u),r2=Fin...
分类:
其他好文 时间:
2014-07-01 08:13:34
阅读次数:
201
题目
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it witho...
分类:
其他好文 时间:
2014-07-01 06:24:42
阅读次数:
204
题目
Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it...
分类:
其他好文 时间:
2014-07-01 06:23:24
阅读次数:
334