More and more things are exposed, but they are not flexible enough. In the past, all such questions were violent, enumerative, and two for loops, today, when I saw it, I went on to think that the violence would time out, but several people had already passed 200 + Ms. I have been deriving it, proving that the more difficult it was to push, I have not made a question. In fact, this question is very simple.Algorithm), A for loop, enumerative the number of A, and then according to profit = A * A + B * B-A * A-B * B, is the quadratic function of y, based on the maximum value of Image B = B/2 and then the axis, the two sides decrease progressively.
# Include <cstdio> # include <iostream> # include <cstring> # include <cstdlib> using namespace STD; int main () {// freopen ("in.txt ", "r", stdin); Double A, B, Maxx; int K, a, B; scanf ("% lf % d", & A, & B, & K); Maxx =-100000; a = 0; B = 0; For (INT I = 0; I <= K; I ++) {int y = B/2; double temp; If (Y + I> K) y = k-I; If (Y <0) y = 0; temp = A * I + B * Y-I * I-y * Y; If (temp> Maxx) {Maxx = temp; A = I; B = y ;}} printf ("%. 2lf \ n % d \ n ", Maxx, a, B); Return 0 ;}
The algorithm of pure brute-force enumeration.
# Include <cstdio> # include <iostream> # include <cstring> # include <cstdlib> using namespace STD; int main () {// freopen ("in.txt ", "r", stdin); Double A, B, Maxx; int A = 0, B = 0, K; Maxx =-100000; scanf ("% lf % d", & A, & B, & K); For (INT I = 0; I <= K; I ++) {for (Int J = 0; j + I <= K; j ++) {double temp = A * I + B * j-I * I-j * j; if (temp> Maxx) {Maxx = temp; A = I; B = J ;}} printf ("%. 2lf \ n % d \ n ", Maxx, a, B); Return 0 ;}