A.Only Pluses (枚举)
题意:
给出三个整数 aaa 、 bbb 和 ccc 可以执行以下操作最多 555 次。
- 挑选其中一个整数;
- 将其增加 111 。
通过这些操作可以实现的 a×b×ca \times b \times ca×b×c 的最大值是多少?
分析:
枚举a,b,ca,b,ca,b,c三个数在操作之后的值即可。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n'
#define PII pair<LL, LL>
const int maxn = 805;
const int INF = 1e9;
const int mod = 998244353;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--)
{
int a, b, c;
cin >> a >> b >> c;
int ans = a * b * c;
for (int i = a; i <= a + 5; i++)
{
for (int j = b; j <= b + 5; j++)
{
for (int k = c; k <= c + 5; k++)
{
if (i + j + k - (a + b + c) <= 5)
ans = max(ans, i * j * k);
}
}
}
cout << ans << endl;
}
return 0;
}
B.Angry Monk (模拟)
题意:
给出一个数组,每次操作可以将数组中的一个数xxx分成x−1x-1x−1和111,或者将一个数xxx和一个111合并,问最少多少次操作可以将数组中所有数合并成一个。
分析:
我们从小到大将除了最大值的每个数字xxx分成xxx个111,再将他们全都合并到最大的数字上,每个数字的贡献是2×x−12 \times x-12×x−1。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define endl '\n'
#define PII pair<LL, LL>
const int maxn = 805;
const int INF = 1e9;
const int mod = 998244353;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
while (T--)
{
int n, k, mx = 0;
cin >> n >> k;
int ans = 0;
for (int i = 1; i <= k; i++)
{
int tmp;
cin >> tmp;
mx = max(mx, tmp);
ans += 2 * tmp - 1;
}
cout << ans - 2 * mx + 1 << endl;
}
return 0;
}
C. Gorilla and Permutation (贪心)
题意:
给出三个数字 nnn 、 mmm 和 kkk。他们决定构造一个长度为 nnn 的排列。
对于该排列, g(i)g(i)g(i) 是长度为 iii 的前缀上排列中所有不大于 mmm 的数字之和。其中 f(i)f(i)f(i) 是长度为 iii 的前缀上排列中所有不小于 kkk 的数字之和。长度为 iii 的前缀是由原始数组的前 iii 个元素组成的子数组。
例如,如果 n=5n = 5n=5 、 m=2m = 2m=2 、 k=5k = 5k=5 ,且排列为 [5,3,4,1,2][5, 3, 4, 1, 2][5,3,4,1,2] ,则:
- f(1)=5f(1) = 5f(1)=5 ,因为 5≥55 \ge 55≥5 ; g(1)=0g(1) = 0g(1)=0 ,因为 5>25 > 25>2 ;
- f(2)=5f(2) = 5f(2)=5 ,因为 3<53 < 53<5 ; g(2)=0g(2) = 0g(2)=0 ,因为 3>23 > 23>2 ;
- f(3)=5f(3) = 5

最低0.47元/天 解锁文章
1724

被折叠的 条评论
为什么被折叠?



