Algorithm notes

来源:互联网 发布:炉石淘宝买卡包安全吗 编辑:程序博客网 时间:2024/06/05 16:20
2013/03/31 Confirming a point is in a triangle (2D)
---------------------------------------------------------------------------------
Directed area formula :
|  x0 y0 1  |
|  x1 y1 1  |    =  2A  =  x0*y1 + y0*x2 + y2*x1 - y1*x2 - y0*x1 - x0*y2
|  x2 y2 1  |
("A" represents the area, (x0,y0) & (x1,y1) & (x2, y2) are points of the triangle.)

Assuming that (x,y) is the point we want to confirm, calculate area "B":
          |  x   y  1  |             |  x0 y0 1  |             |  x0 y0 1  |
2B =   |  x1 y1 1 |     +      |  x   y   1  |     +      |  x1 y1 1  |           Then judge if 2B == 2A.
          |  x2 y2 1 |             |  x2 y2 1  |             |  x   y   1  |

2013/03/30  Finding the longest palindrome substring
---------------------------------------------------------------------------------
Manacher algorithm :
The core idea is to fill the string with '#' like:

source string :     abcccba
filled string     :     #a#b#c#c#c#b#a#

Then you can find the length of the filled string is always odd, so you needn't to consider the condition of even.
Store the middle position in the substring you are to judge and the radious the substring contains.

2013/03 Fibonacci solution by martix
2013/03 Hanoi recursion
2013/03 Binary GCD(Greatest common divisor)
原创粉丝点击