By Long Luo

# 神经网络是如何工作的？

$S(x) = {\frac {1}{1 + e^{-x}}} = {\frac {e^{x}}{e^{x} + 1}} = 1 - S(-x)$

By Frank Luo

This is my answers of the MRI Tutorial Videos How MRI Works - Part 2: The Spin Echo and How MRI Works - Part 3：Fourier Transform and K-Space .

## Part 2: The Spin Echo

### Questions

#### Question 1：

1. The Boltzmann Magetization $M_0 = \frac{N {\gamma}^2 \hbar^2 B_0}{4 k T}$, then after elimination the units is $J/T$.
2. The Polarization is $P = \frac{\gamma \hbar B_0}{2kT}$, then after elimination we can get that $P$ is a special number depends on the material, no SI units.

#### Question 2：

1. The polarization is $P = \frac{51-49}{100} = 0.02$ .
2. The magnet field strength should be $B_0 = \frac{0.02}{0.0000034} \approx 5882T$ .
3. The temperature should be $T = \frac{300 \times 0.0000034}{0.02} = 0.051K$.

#### Question 3：

1. Since the Boltzmann Magetization Equation is $M = M_0(1- e^{-\frac{t}{T_1}}) e^{-\frac{t}{T_2}}$ , so we can calculate the signal.

The signal of Tissue $A$ : $M_A = M_0(1- e^{-\frac{150}{300}}) e^{-\frac{12.5}{20}} = 0.21$ .
The signal of Tissue $B$ : $M_B = M_0(1- e^{-\frac{150}{200}}) e^{-\frac{12.5}{40}} = 0.38$ .

Surely Tissue $B$ will deliver more signal.

1. We have calculated that Tissue $B$ will deliver more signal if both Tissue $A$ and $B$ has the same Boltzmann Magetization.

If Tissue $A$ is $85\%$ of Tissue $B$, then the Tissue $A$ signal will become lesser, so Tissue $B$ deliver more signal.

1. Let function $f(t) = M_{0A}(1- e^{-\frac{TR}{T_{1A}}})e^{-\frac{t}{T_{2A}}} - M_{0B}(1- e^{-\frac{TR}{T_{1B}}})e^{-\frac{t}{T_{2B}}}$ reprent the signal of time $t$.

Consider the function: $f(t) = (1 - e^{-\frac{150}{200}}) e^{-\frac{t}{40}} - (1- e^{-\frac{150}{300}}) e^{-\frac{t}{20}}$ reaches its PEAK at about $t = 16$, so the $TE$ should be $TE = 32ms$.

By Long Luo

# 贝塞尔曲线是什么？

http://www.longluo.me/projects/bezier/

# 贝塞尔曲线的数学原理

## 这一章节待完善！！！

$P_1(x_1, y_1)$$P_2(x_2, y_2)$

$\begin{cases} x = x_1 + t (x_2 - x_1) \\ y = y_1 + t (y_2 - y_1) \end{cases}$

$B(t) = P_0 + (P_1 - P_0)t= (1-t)P_0 + tP_1, t\in [0,1]$

$B(t) = \sum_{i=0}^{n} \binom{n}{i}P_i(1 - t)^{n-i}t^i = \binom{n}{0}P_0(1-t)^{n}t^0 + \binom{n}{1}P_1(1-t)^{n-1}t^1 + \cdots + \binom{n}{n-1}P_{n-1}(1-t)^{n-1}t^{n-1} + \binom{n}{n}P_{n}(1-t)^{n}t^{n}, t\in[0,1]$

$P_0^{n} = (1 - t)P_0^{n-1} + tP_1^{n-1}, t\in [0,1]$

# 贝塞尔曲线的缺点

1. 高度精确的曲线：贝塞尔曲线是由有限个控制点所定义的，当需要绘制极其精确的曲线时，可能无法满足需求；
2. 曲率变化较大的曲线：贝塞尔曲线的控制点数量决定了曲线的平滑程度。在曲率变化较大的情况下，可能需要增加更多的控制点来准确描述曲线的形状；
3. 特殊曲线类型：某些特殊曲线类型，如圆或椭圆等，可能有更适合的数学表示方法，而不是使用贝塞尔曲线。

By Long Luo

# Intuition

It’s easy to think of using a Hash Table to achieve $O(1)$ time complexity for $\texttt{insert}$ and $\texttt{remove}$ operations. However, we need $O(1)$ time complexity to complete the $\texttt{getRandom}$ operation.

The Array structure can complete the operation of obtaining random elements in $O(1)$ time complexity, but it can’t completed the $\texttt{insert}$ and $\texttt{remove}$ operations in $O(1)$ time complexity.

So How?

Aha!!!

By Long Luo

• 小于 $x$ 的数有 $a$ 个；
• 等于 $x$ 的数有 $b$ 个；
• 大于 $x$ 的数有 $c$ 个。

By Long Luo

# Intuition

We can find that this is a graph theory problem with analysis.

Imagine the stone on the 2D coordinate plane as the vertex of the graph, If the x-coord or the y-coord of two stones are the same, there is an edge between them.

This can be show as follows:

According to the rule that stones can be removed, we should remove those points that are in the same row or column with other points as late as possible. That is, the more points in the same row or column with point A, the later point A should be removed. In this way, we can delete as many points as possible through point A.

It can be found that all vertices in a connected graph can be deleted to only one vertex.

Since these vertices are in a connected graph, all vertices of the connected graph can be traversed by DFS or BFS.

Therefore: the maximum number of stones that can be removed = the number of all stones - the number of connected components.

By Long Luo

# Intuition

We can simply use a $\texttt{ArrayList}$ to record the number and sort the list, then we can easily get the median element of the list. However, the Time Complexity will be $O(n^2logn)$ and the Space Complexity is $O(n)$.

It surely will be TLE and we have to find a better solution.

# Heap

We can use Two Priority Queues (Heaps) to maintain the data of the entire data stream.

The min Heap denoted as $\textit{queueMin}$ is used to maintain the number $\textit{num} \leq \textit{median}$. The max Heap denoted as $\textit{queueMax}$ is used to maintain the number $\textit{num} \gt \textit{median}$.

• When the total number of data stream elements is Even: $\texttt{queueMax.size()} = \texttt{queueMin.size()}$, the dynamic median is $\frac{\texttt{queueMax.peek()} + \texttt{queueMin.peek()}}{2}$;

• When the total number of data stream elements is Odd: $\texttt{queueMin.size()} = \texttt{queueMin.size()} + 1$, the dynamic median is $\texttt{queueMin.peek()}$.

By Long Luo

# 思路

1. API：使用 $String$ $API$ $\texttt{contains(CharSequence s)}$ 来判断 $\textit{sequence}$ 中是否存在拼接的 $N$$\textit{word}$ 字符串；
2. KMP: 使用 KMP 算法判断 $\textit{sequence}$ 中是否存在拼接的 $N$$\textit{word}$ 字符串；
3. 暴力：判断是否存在拼接的 $N$$\textit{word}$ ，虽然很简单，但代码要写的优雅简洁有难度。

API 方法最简单，但 KMP 算法比较复杂。看了一些题解里的暴力解法，大多数人的暴力解法写的太复杂。我自己写该题暴力解法也写了 $3$ 个版本，前 $2$ 个版本也很复杂，逐渐优化为目前的简洁优雅版本。

## 复杂度分析

• 时间复杂度：$O(n^2)$ ，其中 $n$ 是字符串 $\textit{sequence}$ 长度，存在 $2$ 个循环，所以总时间复杂度为 $O(n^2)$
• 空间复杂度：$O(1)$

All suggestions are welcome.
If you have any query or suggestion please comment below.
Please upvote👍 if you like💗 it. Thank you:-)

Explore More Leetcode Solutions. 😉😃💗

By Long Luo

# Intution

We can easily find that whether there exists a triple of indices $(i, j, k)$ such that $i < j < k$ and $nums[i] < \textit{nums}[j] < \textit{nums}[k]$ only traversing the array once, but the problem is how to make our mind into algorithms.

# Brute Force

It’s easy to use Brute Force way to solve this problem, but the time complexity is $O(n^3)$, it will TLE, so we need to find a better way.

## Analysis

• Time Complexity: $O(n^3)$
• Space Complexity: $O(1)$

# Dynamic Programming

We can also use DP method to solve it.

Let $dp[i]$ represents the maximum length of a increasing sequence.

$dp[i] = \begin{cases} 1 & dp[i] \le dp[j], 0 < j < i \\ dp[j] + 1 & dp[i] > dp[j], 0 < j < i \end{cases}$

By Long Luo

490. 迷宫 Medium
505. 迷宫 II Medium
499. 迷宫 III Hard

0%