The Beauty of Recursion

Declaration: this article is in long time editing…


Here comes some beautiful recursive solutions to some problems.

Examples

Some of the problems have a very nice recursive structure, we can deal with them just using one step recursion.

Fibonacci Numbers

The first comes very famous Fibonacci Numbers, which is a sequence of 0, 1, 1, 2, 3, 5, 8, 13 … The structure is easily captured, if we use $\text{fib}(n)$ to denote the $n^{\text{th}}$ Fibonacci Number (n is assumed to start from 0). $$ \text{fib}(n) = \begin{cases} n, &\text{ if } n \le 1 \newline \text{fib}(n-1) + \text{fib}(n-2), &\text{ if } n > 1. \end{cases} $$ That is why we can write easily a procedure to compute the fibs. If we use MIT Scheme, we can write as follows:

神奇的位运算

In editing…

必备知识

首先要对原码、反码、补码有一定理解,推荐阅读此文:https://www.cnblogs.com/zhangziqiu/archive/2011/03/30/computercode.html

A collection of some coding problems

场景题

题一:最高得分

一个长度为$N$的序列,玩家每次只能从头部或尾部拿数字,不能从中间拿。拿走的数字依次从左到右排列在自己面前。拿完$N$个数字之后,游戏结束。此时$N$个数字在玩家面前组成一个新的排列,这个数列每相邻两个数字之差的绝对值之和为玩家最终得分。假设玩家前面的$N$个数字从左到右标号为 $n_1,n_2, \dots, n_N$,则最终得分$S$的计算方式如下: $$ S = \text{abs}(n_1-n_2) + \text{abs}(n_2-n_3) + \cdots + \text{abs}(n_{N-1} - n_N). $$

瞎说 KMP 算法

前天做百度笔试,没想到居然出往年的题!哼!更惨的是出了我也不会!我以为只是一个简简单单的字符串匹配,没想到要动用这么难懂的算法。说起来算法导论上也有,只是之前没看到那里。所以,总结一下:我本有好多次机会学习它,然而一次都没有把握。:(

初尝 C++ 类设计

最近在准备笔试,于是在各种网站上刷题嘛。期间做了百度某年的一道 编程题

小 B 最近对电子表格产生了浓厚的兴趣,她觉得电子表格很神奇,功能远比她想象的强大。她正在研究的是单元格的坐标编号,她发现表格单元一般是按列编号的,第 1 列编号为 A,第 2 列为 B,以此类推,第 26 列为 Z。之后是两位字符编号的,第 27 列编号为 AA,第 28 列为 AB,第 52 列编号为 AZ。之后则是三位、四位、五位……字母编号的,规则类似。

LeetCode: Sum of Two Integers

记录一下 LeetCode 做的一道题。要求实现两个整数的加法,但不能使用内置的+-. 原题地址:https://leetcode.com/problems/sum-of-two-integers/

浅谈 Logistic 回归

In editing…

Logistic 回归属于分类模型!!!

从最小二乘说起

线性回归

概率解释

Sigmoid 函数的引入

如果把我比作一张白纸,在我的知识储备中,现在只有线性回归。但是要处理分类问题,我该怎么办?没办法,先考虑一个二分类问题,$y \in {0,1}$,我们准备霸王硬上弓,用回归模型套上去! $$ y = h_{\theta}(x) $$

快速自定义 LaTeX 排版字体

字体设置

在导言区引入fontspec包:\usepackage{fontspec}

使用如下命令自定义字体:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
% 西文默认字体,排版主字体
\setmainfont{}

% 西文无称线字体
\setsansfont{}

% 西文等宽字体
\setmonofont{}

% 数学公式字体
\setmathfont{}

% 中文主字体
\setCJKmainfont[
    Path = fonts/zh_cn/ ,
    BoldFont = HYQiHei-70S.ttf ,
    ItalicFont = HYKaiTiS.ttf ,
    SmallCapsFont = HYQiHei-70S.ttf
    ]{HYQiHei-45S.ttf}

Note:

Linux 使用指北

本文主要引用 Liam Huang 的博客。

系统相关

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
lsb_release -a              # 查看操作系统版本
head -n 1 /etc/issue        # 查看操作系统版本
cat /proc/version           # 查看操作系统内核信息
uname -a                    # 查看操作系统内核信息、CPU 信息
cat /proc/cpuinfo           # 查看 CPU 信息
hostname                    # 查看计算机名字
env                         # 列出环境变量
lsmod                       # 列出加载的内核模块
uptime                      # 查看系统运行时间、负载、用户数量
cat /proc/loadavg           # 查看系统负载