Accurate determination of molecular structures by x-ray absorption spectroscopy