To count World Population in 2015

通过backspace,或者,carriage return,但是不换行,在原来的输出上覆盖新的输出,实现Flying Hello World! 的效果。

$$\cos x=1-{\frac {x^{2}}{2!}}+{\frac {x^{4}}{4!}}-{\frac {x^{6}}{6!}}+\cdots =\sum _{n=0}^{\infty }{\frac {(-1)^{n}x^{2n}}{(2n)!}}$$

A typical example of partial summation. The process will be terminated when the absolute value of the next term is less than \(10^{-6}\).

TIPS:

参考:

NEVER calculate the next term in this way:

1, calculate \(x^{2n}\);

2, calculate \((2n)!\);

3, calculate the division: \(x^{2n} / (2n)!\).

This will lead to OVERFLOW!

The Taylor series of a real or complex-valued function \(f(x)\) that is infinitely differentiable at a real or complex number \(a\) is the power series

$$f(a)+{\frac {f'(a)}{1!}}(x-a)+{\frac {f''(a)}{2!}}(x-a)^{2}+{\frac {f'''(a)}{3!}}(x-a)^{3}+\cdots$$ 

问题描述

在一个路口设置一个探测器,通过通信线路连接到计算机。

  • 路口每通过一辆汽车,探测器向计算机发出一个车辆信号,
  • 探测器每隔单位时间发出一个时钟信号,
  • 观测结束向计算机发出结束信号。

问题求解:

  • 接收探测器发出的信号,
  • 统计出观测的时长、
  • 在观测时长内通过的车辆总数、以及两辆车之间最大的时间间隔。
  • 最后输出结果

Recursion

In computer sciencerecursion is a method of solving a problem where the solution depends on solutions to smaller instances of the same problem. Such problems can generally be solved by iteration, but this needs to identify and index the smaller instances at programming time. Recursion solves such recursive problems by using functions that call themselves from within their own code. The approach can be applied to many types of problems, and recursion is one of the central ideas of computer science.

A recursive function definition has one or more base cases, meaning input(s) for which the function produces a result trivially (without recurring), and one or more recursive cases, meaning input(s) for which the program recurs (calls itself).

Addition

$$\begin{eqnarray}
&&add(0, m) &= m \\
&&add(n+1,m) &= add(n,m)+1
\end{eqnarray}$$

Or

$$\begin{equation}
add(n, m)=\left\{
\begin{array}{ll}
m & \text{if } n = 0 \\
add(n-1,m)+1 & \text{if } n > 0
\end{array}
\right.
\end{equation}$$

程序设计到底设计什么?

  • 1,需求分析
  • 2,抽象模型:数据表示方法,问题的数学模型
  • 3,数据结构设计(变量名命名、数据类型设计、小技巧设计)
  • 4,算法设计:解的设计、流程图
  • 5,语义分析:测试用例设计

Problem Size

Problems in computer world are characterized with size, that is the number of data items in the problem.

A problem of size \(n\) can be considered as a sub problem of size \(n-1\) and one more data item. While a solution to the sub-problem of size \(n-1\) and the nth data item can be used to construct a solution to the original problem of size \(n\).

Given an integer:

1,Divisibility: Is the number devisible by some other integer?

2, Length: How many digits are there in the number?

3, Reverse the integer: 123 --> 321

4,

Scenario

When we want to test whether a number \(p\) is a prime, we need to divide \(p\) with all numbers between \(2\) and \(p-1\). If none of these numbers divides \(p\), then we can conclude that p is a prime.