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:
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?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:
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?
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.
For each test case, output a single integer — the maximum amount of bananas Noobish_Monk can get.
Example
input |
---|
2 |
2 3 4 |
10 1 10 |
output |
---|
100 |
600 |
具体见文后视频。
#include #define fi first #define se second #define int long long using namespace std; typedef pair PII; typedef long long LL; void solve() { int a, b, c; cin >> a >> b >> c; int res = 0; for (int i = 0; i <= 5; i ++) for (int j = 0; j <= 5 - i; j ++) for (int k = 0; k <= 5 - i - j; k ++) res = max(res, (a + i) * (b + j) * (c + k)); cout << res << endl; } signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); int dt; cin >> dt; while (dt --) solve(); return 0; }
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:
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:
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,…,ak ( 1 ≤ a i ≤ n − 1 1 \le a_i \le n - 1 1≤ai≤n−1, ∑ a i = n \sum a_i = n ∑ai=n) — lengths of pieces of casserole, which Noobish_Monk has cut.
It is guaranteed that the sum of k k k over all t t t test cases doesn’t exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2⋅105.
For each test case, output the minimum number of operations K1o0n needs to restore his pie after the terror of Noobish_Monk.
Example
input |
---|
4 |
5 3 |
3 1 1 |
5 2 |
3 2 |
11 4 |
2 3 1 5 |
16 6 |
1 6 1 1 1 6 |
output |
---|
2 |
3 |
9 |
15 |
具体见文后视频。
#include #define fi first #define se second #define int long long using namespace std; typedef pair PII; typedef long long LL; const int N = 1e5 + 10; int n, k; int a[N]; void solve() { cin >> n >> k; for (int i = 1; i <= k; i ++) cin >> a[i]; sort(a + 1, a + 1 + k); int res = 0, tot = 0; for (int i = 1; i < k; i ++) res += a[i] - 1, tot += a[i]; cout << res + tot << endl; } signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); int dt; cin >> dt; while (dt --) solve(); return 0; }
Gorilla and Noobish_Monk found three numbers n n n, m m m, and k k k ( m < k m < k m For the permutation, Noobish_Monk came up with the following function: g ( i ) g(i) g(i) is the sum of all the numbers in the permutation on a prefix of length i i i that are not greater than m m m. Similarly, Gorilla came up with the function f f f, where f ( i ) f(i) f(i) is the sum of all the numbers in the permutation on a prefix of length i i i that are not less than k k k. A prefix of length i i i is a subarray consisting of the first i i i elements of the original array. For example, if n = 5 n = 5 n=5, m = 2 m = 2 m=2, k = 5 k = 5 k=5, and the permutation is [ 5 , 3 , 4 , 1 , 2 ] [5, 3, 4, 1, 2] [5,3,4,1,2], then: Help them find a permutation for which the value of ( ∑ i = 1 n f ( i ) − ∑ i = 1 n g ( i ) ) \left(\sum_{i=1}^n f(i) - \sum_{i=1}^n g(i)\right) (∑i=1nf(i)−∑i=1ng(i)) is maximized. † ^{\dagger} †A permutation of length n n n is an array consisting of n n n distinct integers from 1 1 1 to n n n in any order. For example, [ 2 , 3 , 1 , 5 , 4 ] [2,3,1,5,4] [2,3,1,5,4] is a permutation, but [ 1 , 2 , 2 ] [1,2,2] [1,2,2] is not a permutation (as 2 2 2 appears twice in the array) and [ 1 , 3 , 4 ] [1,3,4] [1,3,4] is also not a permutation (as n = 3 n=3 n=3, but 4 4 4 appears in the array). The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1≤t≤104) — the number of test cases. The only line of each case contains three integers n n n, m m m, k k k ( 2 ≤ n ≤ 1 0 5 2\le n \le 10^5 2≤n≤105; 1 ≤ m < k ≤ n 1 \le m < k \le n 1≤m It is guaranteed that the sum of n n n over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2⋅105. For each test case, output the permutation — a set of numbers that satisfies the conditions of the problem. If there are multiple solutions, output any of them. In the first example, ( ∑ i = 1 n f ( i ) − ∑ i = 1 n g ( i ) ) = 5 ⋅ 5 − ( 0 ⋅ 3 + 1 + 3 ) = 25 − 4 = 21 \left(\sum_{i=1}^n f(i) - \sum_{i=1}^n g(i)\right) = 5 \cdot 5 - (0 \cdot 3 + 1 + 3) = 25 - 4 = 21 (∑i=1nf(i)−∑i=1ng(i))=5⋅5−(0⋅3+1+3)=25−4=21 具体见文后视频。 ErnKor is ready to do anything for Julen, even to swim through crocodile-infested swamps. We decided to test this love. ErnKor will have to swim across a river with a width of 1 1 1 meter and a length of n n n meters. The river is very cold. Therefore, in total (that is, throughout the entire swim from 0 0 0 to n + 1 n+1 n+1) ErnKor can swim in the water for no more than k k k meters. For the sake of humanity, we have added not only crocodiles to the river, but also logs on which he can jump. Our test is as follows: Initially, ErnKor is on the left bank and needs to reach the right bank. They are located at the 0 0 0 and n + 1 n+1 n+1 meters respectively. The river can be represented as n n n segments, each with a length of 1 1 1 meter. Each segment contains either a log ‘L’, a crocodile ‘C’, or just water ‘W’. ErnKor can move as follows: Determine if ErnKor can reach the right bank. The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1≤t≤104) — the number of test cases. The first line of each test case contains three numbers n , m , k n, m, k n,m,k ( 0 ≤ k ≤ 2 ⋅ 1 0 5 0 \le k \le 2 \cdot 10^5 0≤k≤2⋅105, 1 ≤ n ≤ 2 ⋅ 1 0 5 1 \le n \le 2 \cdot 10^5 1≤n≤2⋅105, 1 ≤ m ≤ 10 1 \le m \le 10 1≤m≤10) — the length of the river, the distance ErnKor can jump, and the number of meters ErnKor can swim without freezing. The second line of each test case contains a string a a a of length n n n. a i a_i ai denotes the object located at the i i i-th meter. ( a i ∈ { a_i \in \{ ai∈{‘W’,‘C’,‘L’ } \} }) It is guaranteed that the sum of n n n over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2⋅105. For each test case, output “YES” if ErnKor can pass the test, and output “NO” otherwise. You can output the answer in any case (upper or lower). For example, the strings “yEs”, “yes”, “Yes”, and “YES” will be recognized as positive responses. Example Let’s consider examples: 具体见文后视频。 One of the first programming problems by K1o0n looked like this: “Noobish_Monk has n n n ( 1 ≤ n ≤ 100 ) (1 \le n \le 100) (1≤n≤100) friends. Each of them gave him a a a ( 1 ≤ a ≤ 10000 ) (1 \le a \le 10000) (1≤a≤10000) apples for his birthday. Delighted with such a gift, Noobish_Monk returned b b b ( 1 ≤ b ≤ min ( 10000 , a ⋅ n ) ) (1 \le b \le \min(10000, a \cdot n)) (1≤b≤min(10000,a⋅n)) apples to his friends. How many apples are left with Noobish_Monk?” K1o0n wrote a solution, but accidentally considered the value of n n n as a string, so the value of n ⋅ a − b n \cdot a - b n⋅a−b was calculated differently. Specifically: Learning about this, ErnKor became interested in how many pairs ( a , b ) (a, b) (a,b) exist for a given n n n, satisfying the constraints of the problem, on which K1o0n’s solution gives the correct answer. “The solution gives the correct answer” means that it outputs a non-empty string, and this string, when converted to an integer, equals the correct answer, i.e., the value of n ⋅ a − b n \cdot a - b n⋅a−b. The first line contains a single integer t t t ( 1 ≤ t ≤ 100 1 \le t \le 100 1≤t≤100) — the number of test cases. For each test case, a single line of input contains an integer n n n ( 1 ≤ n ≤ 100 1 \le n \le 100 1≤n≤100). It is guaranteed that in all test cases, n n n is distinct. For each test case, output the answer in the following format: In the first line, output the integer x x x — the number of bad tests for the given n n n. In the next x x x lines, output two integers a i a_i ai and b i b_i bi — such integers that K1o0n’s solution on the test “ n n n a i a_i ai b i b_i bi” gives the correct answer. In the first example, a = 20 a = 20 a=20, b = 18 b = 18 b=18 are suitable, as “ 2 \text{2} 2” ⋅ 20 − 18 = \cdot 20 - 18 = ⋅20−18= “ 22222222222222222222 \text{22222222222222222222} 22222222222222222222” − 18 = 22 = 2 ⋅ 20 − 18 - 18 = 22 = 2 \cdot 20 - 18 −18=22=2⋅20−18 具体见文后视频。 In his favorite cafe Kmes once again wanted to try the herring under a fur coat. Previously, it would not have been difficult for him to do this, but the cafe recently introduced a new purchasing policy. Now, in order to make a purchase, Kmes needs to solve the following problem: n n n cards with prices for different positions are laid out in front of him, on the i i i-th card there is an integer a i a_i ai, among these prices there is no whole positive integer x x x. Kmes is asked to divide these cards into the minimum number of bad segments (so that each card belongs to exactly one segment). A segment is considered bad if it is impossible to select a subset of cards with a product equal to x x x. All segments, in which Kmes will divide the cards, must be bad. Formally, the segment ( l , r ) (l, r) (l,r) is bad if there are no indices i 1 < i 2 < … < i k i_1 < i_2 < \ldots < i_k i1 Help Kmes determine the minimum number of bad segments in order to enjoy his favorite dish. The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 3 1 \le t \le 10^3 1≤t≤103) — the number of test cases. The first line of each set of input data gives you 2 2 2 integers n n n and x x x ( 1 ≤ n ≤ 1 0 5 , 2 ≤ x ≤ 1 0 5 1 \le n \le 10^5, 2 \le x \le 10^5 1≤n≤105,2≤x≤105) — the number of cards and the integer, respectively. The second line of each set of input data contains n n n integers a i a_i ai ( 1 ≤ a i ≤ 2 ⋅ 1 0 5 , a i ≠ x 1 \le a_i \le 2 \cdot 10^5, a_i \neq x 1≤ai≤2⋅105,ai=x) — the prices on the cards. It is guaranteed that the sum of n n n over all sets of test data does not exceed 1 0 5 10^5 105. For each set of input data, output the minimum number of bad segments. 具体见文后视频。 K1o0n gave you an array a a a of length n n n, consisting of numbers 1 , 2 , … , n 1, 2, \ldots, n 1,2,…,n. Accept it? Of course! But what to do with it? Of course, calculate MEOW ( a ) \text{MEOW}(a) MEOW(a). Let MEX ( S , k ) \text{MEX}(S, k) MEX(S,k) be the k k k-th positive (strictly greater than zero) integer in ascending order that is not present in the set S S S. Denote MEOW ( a ) \text{MEOW}(a) MEOW(a) as the sum of MEX ( b , ∣ b ∣ + 1 ) \text{MEX}(b, |b| + 1) MEX(b,∣b∣+1), over all distinct subsets b b b of the array a a a. Examples of MEX ( S , k ) \text{MEX}(S, k) MEX(S,k) values for sets: The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1≤t≤104) — the number of test cases. In a single line of each test case, an integer n n n ( 1 ≤ n ≤ 5000 1 \le n \le 5000 1≤n≤5000) is entered, the size of the array of gifted numbers. It is guaranteed that the sum of n 2 n^2 n2 over all test cases does not exceed 25 ⋅ 1 0 6 25 \cdot 10^6 25⋅106. For each test case, output a single number — MEOW ( a ) \text{MEOW}(a) MEOW(a). Since it may be very large, output it modulo 1 0 9 + 7 10^9 + 7 109+7. 具体见文后视频。 Codeforces Round 957 (Div. 3)(A ~ G 题讲解) 最后祝大家早日Input
Output
Example
input 3 5 2 5 3 1 3 10 3 8 output 5 3 4 1 2 3 2 1 10 9 8 4 7 5 6 1 2 3 Note
Solution
Code
#include
D. Test of Love
Problem Statement
Input
Output
Example
input 6 6 2 0 LWLLLW 6 1 1 LWLLLL 6 1 1 LWLLWL 6 2 15 LWLLCC 6 10 0 CCCCCC 6 6 1 WCCCCW output YES YES NO NO YES YES Note
Solution
Code
#include
E. Novice’s Mistake
Problem Statement
Input
Output
Example
input 3 2 3 10 output 3 20 18 219 216 2218 2214 1 165 162 1 1262 2519 Note
Solution
Code
#include
F. Valuable Cards
Problem Statement
Input
Output
Example
input 8 6 4 2 3 6 2 1 2 9 100000 50000 25000 12500 6250 3125 2 4 8 16 5 2 1 1 1 1 1 8 6 4 3 4 3 4 3 4 3 7 12 6 11 1 3 11 10 2 10 5 2 4 4 2 4 4 4 3 1 1 7 8 4 6 5 1 2 4 1 8 27 3 9 17 26 2 20 9 3 output 3 2 1 1 2 1 3 3 Solution
Code
#include
G. Ultra-Meow
Problem Statement
Input
Output
Example
input 5 2 3 4999 5 1 output 12 31 354226409 184 4 Solution
Code
#include
视频讲解
上一篇:2024,小鹏汽车穿越火线
下一篇:识别视频中的人数并统计出来