High-Precision Algorithms for Constructing Optimal Trajectories via Solving Hamiltonian Systems