A Representation Formula of the Viscosity Solution of the Contact Hamilton-Jacobi Equation and Its Applications