To be honest... if you want to accurately calculate that, I think line
integrals are the only way. The problem is, if you're going to account for
the minimal change in density, you might as well also take into
consideration that the path the light follows will not be straight, due to
refraction.
The easiest way to do this, would be to use the fact that the change in
density is miniscule over the height of a 30 story building. Because of this,
even if the entire path of the light from ship to building top were to pass
through the lowest possible density (density atop the building), this path
would still be longer than the other path from ship to observer on the shoreline.