The invention relates to an AUV shape optimization method based on an improved graffiti algorithm, and the method comprises the steps that: the main body shape design of an AUV is divided into three parts: a bow curve, a central curve, and a stern curve segment, the mathematical model is used for controlling the shape of the AUV through six parameters, the value of a resistance coefficient is obtained through fluid calculation, the six parameters are iteratively optimized through an improved graffiti algorithm, and the six optimal control parameters are found. According to the invention, in adesign space, based on the resistance coefficient, a more optimized AUV shape can be found.Compared with a traditional graffiti algorithm, an inverse-based learning strategy is introduced, the local search capability is enhanced, and a more optimized shape can be found in a design space based on a resistance coefficient. Compared with a traditional graffiti algorithm, another small parameter is introduced, the graffiti random flight capacity is reserved, population diversity is improved, optimization can be prevented from falling into local optimum, and a better optimization result is obtained.