牛客挑战赛59 A

小木桩之间是相互独立的,即在大木桩之间插入的每一个小木桩对其他小木桩没有影响,因为当有一个小木桩插入完成后,再插入一个新的小木桩不会影响前面的小木桩对答案的贡献。
对于每一个小木桩,设它安插的位置前面有 x x x 个大木桩,则其后有 a − x a - x a−x 个大木桩,则这个小木桩对答案的贡献为 x × ( a − x ) − x x \times (a - x) - x x×(a−x)−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×(a−xmax)−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;
}
本文来自博客园,作者:correct,转载请注明原文链接:https://www.cnblogs.com/correct/p/16548385.html

浙公网安备 33010602011771号