number of one one function function from $P$ to $Q$ such that $g(1)\neq 0$ 
If $P = \{1,2,3,4,5\}$ and $Q = \{0,1,2,3,4,5\}$. The number of one one function function from
$P$ to $Q$ such that $g(1)\neq 0$ and $g(i)\neq i$ for $i=1,2,3,4,5$ is?

My attempt: Since $g(1) \neq 0,1$, $g(1)$ can take any $4$ values as $2,3,4,5$, which can be done in $4$ ways. Now $g(2),g(3),g(4),g(5)$ can take the remaining $5$ values which can be done in $\displaystyle \binom{5}{4}\cdot 4!$ ways. As such, the number of one-one functions such that $g(1)\neq0,1$ equals:
$$\displaystyle 4\cdot \binom{5}{4}\cdot 4! = 480$$
How can I find the number of functions for which $g(i) \neq i$ for $i = 2, 3, 4, 5$?

You can use the inclusion-exclusion principle to solve this question. First consider all $6! = 720$ permutations of $0, 1, 2, 3, 4, 5$, and discard the last digit. We then remove disallowed permutations step by step, considering the $i^{th}$ digit in the permutation. In the first step we remove all permutations containing a 0 or 1 in $1^{st}$ position. Then, in the second step, we subtract all possible permutations with a 2 in $2^{nd}$ position, and add again all permutations containing a 0 or a 1 in $1^{st}$ position and a 2 in $2^{nd}$ position, since these were already eliminated in the first step. Removing invalid permutations one by one, we get:


*

*Permutations containing a 0 or 1 in $1^{st}$ position: $$720 - 2 \cdot 5! = 480$$

*Permutations containing a 2 in $2^{nd}$ position: $$480 - 5! + 2 \cdot 4! = 408$$

*Permutations containing a 3 in $3^{rd}$ position: $$408 - 5! + 2 \cdot 4! + 4! - 2 \cdot 3! = 348$$

*Permutations containing a 4 in $4^{th}$ position: $$348 - 5! + 2 \cdot 4! + 4! + 4! - 2 \cdot 3! - 2 \cdot 3! - 3 \cdot 2 + 2 \cdot 2 = 298$$

*Permutations containing a 5 in $5^{th}$ position: $$348 - 5! + 2 \cdot 4! + 4! + 4! + 4! - 2 \cdot 3! - 2 \cdot 3! - 2 \cdot 3! - 3 \cdot 2 - 3 \cdot 2 - 3 \cdot 2 + 2 \cdot 2 + 2 \cdot 2 + 2 \cdot 2 + 2 - 2 = 256$$
If you would like to verify these results, you can use the following Python script:
from itertools import permutations

d = [0] * 5
for p in permutations(range(6)):
  for i in range(5):
    if p[0] != 0 and p[i] != i + 1:
      d[i] += 1
    else:
      break

for r in d:
  print(r)

