Codeforces Round 957 (Div. 3) A~G

A.Only Pluses (枚举)

题意:

给出三个整数 a a a b b b c c c 可以执行以下操作最多 5 5 5 次。

  • 挑选其中一个整数;
  • 将其增加 1 1 1

通过这些操作可以实现的 a × b × c a \times b \times c a×b×c 的最大值是多少?

分析:

枚举 a , b , c a,b,c a,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 (模拟)

题意:

给出一个数组,每次操作可以将数组中的一个数 x x x分成 x − 1 x-1 x1 1 1 1,或者将一个数 x x x和一个 1 1 1合并,问最少多少次操作可以将数组中所有数合并成一个。

分析:

我们从小到大将除了最大值的每个数字 x x x分成 x x x 1 1 1,再将他们全都合并到最大的数字上,每个数字的贡献是 2 × x − 1 2 \times x-1 2×x1

代码:

#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 (贪心)

题意:

给出三个数字 n n n m m m k k k。他们决定构造一个长度为 n n n 的排列。

对于该排列, g ( i ) g(i) g(i) 是长度为 i i i 的前缀上排列中所有不大于 m m m 的数字之和。其中 f ( i ) f(i) f(i) 是长度为 i i i 的前缀上排列中所有不小于 k k k 的数字之和。长度为 i i i 的前缀是由原始数组的前 i i i 个元素组成的子数组。

例如,如果 n = 5 n = 5 n=5 m = 2 m = 2 m=2 k = 5 k = 5 k=5 ,且排列为 [ 5 , 3 , 4 , 1 , 2 ] [5, 3, 4, 1, 2] [5,3,4,1,2] ,则:

  • f ( 1 ) = 5 f(1) = 5 f(1)=5 ,因为 5 ≥ 5 5 \ge 5 55 g ( 1 ) = 0 g(1) = 0 g(1)=0 ,因为 5 > 2 5 > 2 5>2
  • f ( 2 ) = 5 f(2) = 5 f(2)=5 ,因为 3 < 5 3 < 5 3<5 g ( 2 ) = 0 g(2) = 0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值