No.627 Trajectory of a Random Walk
Problem Statement
A random walk generally refers to a motion in which the next position is determined randomly.
Here, consider the following random walk of a point P on a number line.
・At time $t=0$, point P is at the origin.
・When P is at coordinate $x$ at some time $t$, at time $(t+1)$ it moves to coordinate $(x+1)$ with probability $\frac{1}{2}$ and to coordinate $(x-1)$ with probability $\frac{1}{2}$.
You are given a sequence $X_i$ of length $T$. Determine whether this sequence can be a record, in order, of the coordinates of point P from time $1$ to time $T$.
Input
T X_1 X_2 ... X_T
$1 \le T \le 100$
$-100 \le X_i \le 100$
The first line contains the length $T$ of the sequence.
Each of the following $T$ lines contains the coordinate $X_i$ of P at time $i$.
Output
Print "T" if the sequence $X_i$ can be a record, in order, of the coordinates of point P, and "F" otherwise.
Print a newline at the end.
Sample
Sample 1
Input
3 1 2 1
Output
T
Sample 2
Input
5 -1 -2 0 1 2
Output
F
It cannot move from -2 to 0 in 1 second.
Sample 3
Input
4 0 1 2 1
Output
F
This is invalid because it did not move from coordinate 0 between time 0 and time 1.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
ats5515