Question: Give You A natural number. Split the natural number to maximize the product of each number after the split...
Idea: try to minimize the difference between the number of splits ,,
For details, see: http://blog.himdd.com /? P = 1918
AC code:
# Include <iostream> # include <cstdio> # include <string. h> # define n 1005 using namespace STD; int s [N]; int main () {int N; while (~ Scanf ("% d", & N) {memset (S, 0, sizeof (s); int sum = 0, I; for (I = 2; sum + I <n; + I) {s [I-1] = I; sum + = I;} sum + = I; s [I-1] = I; int M = I-1; If (Sum-N = 0) {for (INT I = 1; I <m; ++ I) printf ("% d ", s [I]); printf ("% d \ n", s [m]);} else if (Sum-N = 1) {for (INT I = 2; I <m; ++ I) printf ("% d", s [I]); printf ("% d \ n", s [m] + 1 );} else if (Sum-N> = 2) {for (INT I = 1; I <m; ++ I) if (s [I]! = Sum-N) printf ("% d", s [I]); printf ("% d \ n", s [m]) ;}} return 0 ;}