牛客挑战赛59 A

题目描述
小木桩之间是相互独立的,即在大木桩之间插入的每一个小木桩对其他小木桩没有影响,因为当有一个小木桩插入完成后,再插入一个新的小木桩不会影响前面的小木桩对答案的贡献。

对于每一个小木桩,设它安插的位置前面有 x x x 个大木桩,则其后有 a − x a - x ax 个大木桩,则这个小木桩对答案的贡献为 x × ( a − x ) − x x \times (a - x) - x x×(ax)x ,它取最大值的时候 x m a x = ⌊ a 2 ⌋ x_{max} =\lfloor \frac{a}{2} \rfloor xmax=2a ,因此每个小木桩的最大贡献都是 x p e r = x m a x × ( a − x m a x ) − x m a x x_{per}=x_{max}\times(a-x_{max})-x_{max} xper=xmax×(axmax)xmax,因此最大的美观值就是 a n s = x p e r × b ans = x_{per}\times b ans=xper×b

#include <bits/stdc++.h>
//#define LOCAL

using namespace std;

long long a, b, T;

int main(){
    
#ifdef LOCAL
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif
    ios::sync_with_stdio(0);

    while (cin >> T){
        while (T--){
            cin >> a >> b;
            cout << ((a / 2) * (a - (a / 2)) - (a / 2)) * b << "\n";
        }
    }

    return 0;
}
posted @ 2022-08-03 19:07  correct  阅读(27)  评论(0)    收藏  举报