A.[简单数学思维递推]
易得m题所组成所有分数集合中极小值m*6 极大值m*9, 因其子和差值均一, 则有若干组合组成连续闭区间[6*m, 9*m]
易推得6数极小时应有其余三数组合极大 则有公式 ans = max(-(n - m * ll(6)) + m, ll(0)) (未化简)
-----------------------------------------------------------------分割线--------------------------------------------------------------------------------
B. [二分答案/数学]
观察其数据范围, 暴力枚举不妥, 可采用二分答案验证或数学方式求解, 验证条件为等差数列求和
ll(mid * (n + n + (mid - 1) * d) / 2) >= m
ll cal(ll mid)
{
return ll(mid * (n + n + (mid - 1) * d) / 2);
}
ll fst = 1, lst = x, mid;
for(int i = 0; i < 30; i++)
{
mid = (fst + lst) / 2;
if(cal(mid) > m)
lst = mid;
else
fst = mid;
}
mid += 10; //范围控制防止整形误差
while(cal(mid - 1) >= m)
mid--;
-------------------------------------------------------------------分割线-------------------------------------------------------------------
C . [基础贪心]
按val大值优先放置, 则结果必定最优
时间复杂度O(n*log2n) + O(n)
-------------------------------------------------------------------分割线-------------------------------------------------------------------
D.[贪心 / 模拟]
最优策略为首先选择待处理数奇数且下一数不为零时, 其次当前数直接选尽
-------------------------------------------------------------------分割线-------------------------------------------------------------------
E.[基础二维差分/前缀和/预处理 不定矩阵指针处理]
不定矩阵处理
1.vector
vector <element> arr[MAXN]; arr[x].push_back(element);
2.矩阵压缩
int retpos(int x, int y) return (x * (m + 1) + y);
3.指针数组
int *rs[MAXN]; for(int i = 0; i < n; ++i) rs[i] = new int[m + 1];
4.主函数内直接开二维数组
int n, m; cin>>n>>m; int arr[n + 1][m + 1];
题解:
-------------------------------------------------------------------分割线-------------------------------------------------------------------
-------------------------------------------------------------------分割线-------------------------------------------------------------------
-------------------------------------------------------------------分割线-------------------------------------------------------------------
-------------------------------------------------------------------分割线-------------------------------------------------------------------
-------------------------------------------------------------------分割线-------------------------------------------------------------------