Codeforces Round 898 (Div. 4) B. Good Kid

  1. 题意
  2. 解决的难点
  3. 代码
  4. 结语

题意

很简单,给定一串数组a,给这个数组最小元素加一,让我们求出该数组各个元素乘积的最大值,举个例子:

\[ 有一个数组a其长度为i,我们需要找出最小值+1,并求出该数组各个元素乘机的最大值:\\ \prod \limits_{i=0}^{a_i} i \\ |1,2,3,4|\\ 1是最小的元素,我们+1变为2\\ 则答案就是2 \times 2 \times 3 \times 4 = 48 \]

解决的难点

1.我们需要进行数组排序 2.我们需要进行连乘运算

代码

void solve()
{
  /* Start Your Show Linus Shyu */
  int n;
  cin >> n;
  vector<int> a(n);
  int ans = 1;
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  //进行sort排序

  sort(a.begin(),a.end());
  //给最小元素+1
  a[0] ++;
  for(int i = 0; i < n; i++)
  {
    //进行乘积
    ans = ans * a[i];
  }  
  cout << ans << endl;
}

结语

NOI2025省队冲击加油


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 xufaxin2022@163.com

💰

Title:Codeforces Round 898 (Div. 4) B. Good Kid

Author:LinusShyu

Created At:2024-07-07, 00:00:00

Updated At:2024-08-04, 20:21:25

Url:http://example.com/2024/07/07/Codeforces-Round-898-Div-4-B/

Copyright: 'Attribution-non-commercial-shared in the same way 4.0' Reprint please keep the original link and author.

×

Help us with donation

github