18. (17 points) Let $a_{1}, a_{2}, \cdots, a_{n}$ be a permutation of the integers 1, 2, $\cdots, n$, and satisfy the following conditions:
(1) $a_{1}=1$;
(2) $\left|a_{i}-a_{i+1}\right| \leqslant 2(i=1,2, \cdots, n-1)$.
Let the number of such permutations be $f(n)$. Find the remainder when $f(2010)$ is divided by 3.
18. Verifiable
$$
f(1)=1, f(2)=1, f(3)=2 \text {. }
$$

Let $n \geqslant 4$. Then $a_{2}=2$ or 3.
For $a_{2}=2$, the number of permutations is $f(n-1)$. This is because by removing the first term and reducing all subsequent terms by 1, a one-to-one correspondence can be established.

For $a_{2}=3$, if $a_{3}=2$, then $a_{4}=4$, so the number of permutations is $f(n-3)$; if $a_{3} \neq 2$, then 2 must be placed after 4, leading to all odd numbers being in ascending order followed by all even numbers in descending order.
Therefore, $f(n)=f(n-1)+f(n-3)+1$.
Let $r(n)$ be the remainder when $f(n)$ is divided by 3. Then
$$
r(1)=r(2)=1, r(3)=2 \text {. }
$$

For $n \geqslant 4$,
$$
r(n) \equiv[r(n-1)+r(n-3)+1](\bmod 3) \text {. }
$$

Thus, $\{r(n)\}$ forms a sequence with a period of 8:
$$
1,1,2,1,0,0,2,0, \cdots \text {. }
$$

Since $2010 \equiv 2(\bmod 8)$, we have
$$
r(2010)=1,
$$

which means the remainder when $f(2010)$ is divided by 3 is 1.