Question Link
Question:Eight passengers sat on a helicopter and asked for the minimum m value of the center of gravity.
Ideas:According to the formula given by the question, we can know that to minimize M, that is, to minimize the sum of MV and MH, we can use a full arrangement, place each value on each seat, and then update the minimum value.
# include
# include
# include
# include
# include
using namespace STD; const int INF = 0x3f3f3f; int A [8]; int main () {While (1) {for (INT I = 0; I <8; I ++) scanf ("% d", & A [I]); If (! A [0] &! A [1] &! A [2] &! A [3] &! A [4] &! A [5] &! A [6] &! A [7]) break; sort (A, A + 8); double min = inf; do {double mV, MH, M; double x1, x2, Y1, Y2; x1 = A [5] + A [6] + A [7]; x2 = A [0] + A [1] + A [2]; y1 = A [2] + A [4] + A [7]; y2 = A [0] + A [3] + A [5]; MV = POW (x1-X2), 2); MH = POW (Y1-Y2), 2); M = SQRT (MV + Mh ); if (min> m) min = m;} while (next_permutation (A, A + 8); printf ("%. 3lf \ n ", min) ;}return 0 ;}