The linear quadratic regulator for periodic hybrid systems