- 博客(161)
- 收藏
- 关注

原创 leetcode刷题记录
Union Find:Friend Circles:Union Find. I used weighting and path compression.Hash:Longest Consecutive SequenceUse Hash (in python it is set) to quickly judge whether an element is in a set.DFS:Knight Probability in ChessboardDFS.
2020-09-07 10:48:56
496
原创 C++ unique_ptr and shared_ptr
You can only call std::dynamic_pointer_cast on shared_ptr. For unique_ptr, you need to dynamic_cast its raw pointer and create a new unique_ptr with it and manully release the base pointer if the cast succeeds.std::move won’t temporarily increase refcoun
2024-02-28 10:02:22
209
原创 C++ Cast
Compile-Time Casts: static_cast, const_cast, and reinterpret_cast are primarily compile-time operations. They do not incur runtime overhead but require care to avoid undefined behavior or other issues.Runtime Casts: dynamic_cast involves runtime checks t
2024-02-20 09:38:11
295
原创 C++ move semantics
Other Tips: The explicit keyword is a valuable tool in C++ for controlling how constructors and conversion operators are invoked, preventing implicit conversions that can lead to subtle bugs or unintended behavior. By making conversions explicit, programme
2024-02-20 07:09:26
691
原创 C++ initialization of vector
https://www.geeksforgeeks.org/initialize-a-vector-in-cpp-different-ways/Create a 2D vector of 5x3 matrix:vector dp (5, vector (3,0))
2022-10-25 11:58:54
967
原创 QuickSelect
QuickSelect AlgorithmTime complexity:(1) Kth largest number: https://stackoverflow.com/questions/5945193/average-runtime-of-quickselect/25796762(2) decrease by a fixed proportion by using median of mediansMedian of Median
2021-06-07 19:48:32
138
原创 GARCH model in python arch package
GARCH model in python arch packagefrom arch import arch_model
2021-01-28 09:09:45
303
原创 Binary indexed tree
Suitable for interval sum or prefix sum.Interval sum is just difference of two prefix sums.Compared with Segment Tree, Binary Indexed Tree requires less space and is easier to implement.BIT needs exactly n extra spaces, but Segment Tree needs approximat
2021-01-19 06:35:56
158
原创 Complete binary tree
Complete binary tree is a special kind of binary tree. It has all the nodes one by one. It does not need to be a full pyramid. Complete binary tree can be stored in an array, which is the main advantage of it. And the parent nodes and child nodes have rela
2021-01-19 06:12:19
212
原创 Top k largest elements:Quick Select vs. Priority Queue
Quick select time complexity is O(n) on average no matter what k is.Priority Queue has time complexity O(nlog(k)).
2021-01-18 09:18:26
117
原创 how to change legend in pandas.df.plot()
You need to use y to specify the columns and then set labels.
2021-01-14 05:57:03
483
1
原创 Adding multiple strings in WHERE clause - SQL
SELECT name, population FROM world WHERE name IN ('france','Germany','Italy');
2021-01-12 09:40:39
118
原创 change column name when using pandas plot
fig, ax = plt.subplots(1,1) (r_p+1).cumprod().plot(ax=ax) (r_bench+1).cumprod().plot(ax=ax) ax.legend(["portfolio", "benchmark"])
2021-01-07 07:14:40
153
原创 pandas plot color
P_c_df.plot(ax=ax[i][0],style="^-", color=["red","green","purple","orange"])
2020-12-28 11:39:15
574
原创 color and type of plot line and dot
You can convey str directly for both color and line type and dot type. If you want to further change the dots’ color, you can set mec, mfc for the edge color and center color of dots separately.
2020-12-21 03:50:12
178
原创 Priority Queue and Heap in Python
Two kinds of priority queue implementation:from queue import PriorityQueueimport heapqHeapqVisit for details: https://docs.python.org/3/library/heapq.htmlHeapq functions are directly applied to list. You can create a normal list, can convey it int.
2020-12-16 16:06:09
151
原创 scipy.optimize.minimize
def fff(x1,x2,x3): return (x1[0]-x2)**2+(x1[1]-x3)**2 result = minimize(fff, [0,1], (1,2)) # x0可以是列表,但只对应相应函数的第一个位置,args必须是tuple,对应所有剩下位置。result.x # 参数拟合值
2020-12-13 14:31:27
425
1
原创 递归和循环
递归优点:逻辑清晰,容易理解,容易写。递归缺点:函数堆栈使用多,时间空间消耗大。循环优点:时间空间消耗小。循环缺点:逻辑复杂,难以理解,难写。尾递归和单向递归都可以写成循环,尤其是尾递归,最好是写成循环,而且也很容易写成循环,甚至可以通过机械的步骤来实现,不少编译器也实现了尾递归直接优化成循环的功能。python3.6未实现尾递归优化,最大递归调用深度是3000左右。...
2020-11-25 03:14:50
290
原创 python各种进制和十进制之间的相互转换
https://www.cnblogs.com/weiliwei-lucky/p/11201428.html
2020-11-24 13:28:52
315
原创 决策单调性
决策单调性定义与证明https://www.cnblogs.com/YSFAC/p/13363203.html详见此文。重点:考虑形如????????(????)=????????????{????????(????)+????(????,????)}的dp。(max类似)其中每一个j都称为一个决策点。定义:一个dp满足决策单调性的充要条件是:对于两个决策点????<????,若在i处y优于x,则在[????+1,????]处y都优于x。定理:若w满足四边形不等式,则dp满足决策单调性
2020-11-03 09:57:05
545
原创 binary search package in python
import bisecta = [1,2,3,4]b = bisect.bisect_left(a,2.5)b # b = 2
2020-10-26 01:20:11
105
原创 Namedtuple
Name the constantsfrom collections import namedtupleGridState = namedtuple('GridState', 'start ending empty obstacle')grid_state = GridState( start = 1, ending = 2, empty = 0, obstacle = -1)
2020-10-25 09:26:53
90
原创 DFS framework
void dfs(){ if(到达中点状态) { ... //根据题意添加 return; } if(越界或不合法状态) return; if(特殊状态) // 剪枝 return; for(扩展方式) { if(扩张方式所到达状态合法) { 修改操作; // 根据题意添加 标记; dfs()
2020-10-25 08:21:32
93
原创 Union Find pros and cons
UF’s biggest pro is that it is convenient to add or delete connections. For example, in Knuth’s MST algorithm, you need to add black edges contiguously, so using UF is good.If you have a fixed shape of graph, DFS can be better than UF.
2020-10-22 02:42:52
123
原创 BFS in python
BFS需要一个marked来记录是否访问过该点,需要记录到达该点所需步数,需要一个队列来存储点。marked可以用dict,但是可以不用一上来先遍历一遍所有点并把它们添加到marked里面然后设置其值为1,而可以在BFS循环时每遇到一个再给里面加一个。记录步数可以不用额外的变量,而可以在队列中直接存储tuple(点,步数)。队列可以使用from queue import Queueq = Queue()也可以使用import collectionsqueue = collections.d
2020-10-21 14:56:02
159
1
原创 把列表转换为字典
创建一个全是空列表的字典:from collections import defaultdicta = [1,2,3]b = defaultdict(list)b["aaa"].append(1) # 可以直接appendb["aaa"]把两个列表的元素对应起来,创建字典:a = [1,2,3]c = [4,5,6]dict(zip(a,c))...
2020-10-21 14:11:47
1724
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人