🚀欢迎来到本文🚀
🍉个人简介:陈童学哦,彩笔ACMer一枚。
🏀所属专栏:Codeforces
本文用于记录回顾总结个人的一些解题思路便于加深理解。
📢📢📢传送阵
A. Only Pluses
Kmes has written three integers a a a, b b b and c c c in order to remember that he has to give Noobish_Monk a × b × c a \times b \times c a×b×c bananas.
Noobish_Monk has found these integers and decided to do the following at most 5 5 5 times:
- pick one of these integers;
- increase it by 1 1 1.
For example, if a = 2 a = 2 a=2, b = 3 b = 3 b=3 and c = 4 c = 4 c=4, then one can increase a a a three times by one and increase b b b two times. After that a = 5 a = 5 a=5, b = 5 b = 5 b=5, c = 4 c = 4 c=4. Then the total number of bananas will be 5 × 5 × 4 = 100 5 \times 5 \times 4 = 100 5×5×4=100.
What is the maximum value of a × b × c a \times b \times c a×b×c Noobish_Monk can achieve with these operations?
Input
Each test contains multiple test cases. The first line of input contains a single integer t t t ( 1 ≤ t ≤ 1000 1 \le t \le 1000 1≤t≤1000) — the number of test cases. The description of the test cases follows.
The first and only line of each test case contains three integers a a a, b b b and c c c ( 1 ≤ a , b , c ≤ 10 1 \le a, b, c \le 10 1≤a,b,c≤10) — Kmes’s integers.
Output
For each test case, output a single integer — the maximum amount of bananas Noobish_Monk can get.
解题思路
暴力枚举即可。
AC代码
#include<bits/stdc++.h>
#define look(x) cout << #x << " == " << x << "\n"
using namespace std;
using i64 = long long;
const int N = 5e5 + 10;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
void solve(){
int a,b,c;
cin >> a >> b >> c;
int ans = a * b * c;
for(int i = 0;i <= 5;i ++){
for(int j = 0;j <= 5;j ++){
for(int k = 0;k <= 5;k ++){
if(i + j + k <= 5){
ans = max(ans,(a + i) * (b + j) * (c + k));
}
}
}
}
cout << ans << "\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while(t --){
solve();
}
return 0;
}
B. Angry Monk
To celebrate his recovery, k1o0n has baked an enormous n n n metres long potato casserole.
Turns out, Noobish_Monk just can’t stand potatoes, so he decided to ruin k1o0n’s meal. He has cut it into k k k pieces, of lengths a 1 , a 2 , … , a k a_1, a_2, \dots, a_k a1,a2,…,ak meters.
k1o0n wasn’t keen on that. Luckily, everything can be fixed. In order to do that, k1o0n can do one of the following operations:
- Pick a piece with length a i ≥ 2 a_i \ge 2 ai≥2 and divide it into two pieces with lengths 1 1 1 and a i − 1 a_i - 1 ai−1. As a result, the number of pieces will increase by 1 1 1;
- Pick a slice a i a_i ai and another slice with length a j = 1 a_j=1 aj=1 ( i ≠ j i \ne j i=j) and merge them into one piece with length a i + 1 a_i+1 ai+1. As a result, the number of pieces will decrease by 1 1 1.
Help k1o0n to find the minimum number of operations he needs to do in order to merge the casserole into one piece with length n n n.
For example, if n = 5 n=5 n=5, k = 2 k=2 k=2 and a = [ 3 , 2 ] a = [3, 2] a=[3,2], it is optimal to do the following:
- Divide the piece with length 2 2 2 into two pieces with lengths 2 − 1 = 1 2-1=1 2−1=1 and 1 1 1, as a result a = [ 3 , 1 , 1 ] a = [3, 1, 1] a=[3,1,1].
- Merge the piece with length 3 3 3 and the piece with length 1 1 1, as a result a = [ 4 , 1 ] a = [4, 1] a=[4,1].
- Merge the piece with length 4 4 4 and the piece with length 1 1 1, as a result a = [ 5 ] a = [5] a=[5].
Input
Each test contains multiple test cases. The first line contains the number of test cases t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1≤t≤104).
Description of each test case consists of two lines. The first line contains two integers n n n and k k k ( 2 ≤ n ≤ 1 0 9 2 \le n \le 10^9 2≤n≤109, 2 ≤ k ≤ 1 0 5 2 \le k \le 10^5 2≤k≤105) — length of casserole and the number of pieces.
The second line contains k k k integers a 1 , a 2 , … , a k a_1, a_2, \ldots, a_k a1,a2,…<