Joey Takes Money

2023-12-02 23:20
文章标签 money takes joey

本文主要是介绍Joey Takes Money,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Joey Takes Money

题面翻译

  • 题目翻译如下

题目描述

Joey 很穷,因此他的朋友 Chandler 想要借给他一些钱。但是 Joey 的自尊心很强,为了不让他的自尊心受挫又能给他钱,Chandler 打算和他玩一个游戏。

在这个游戏中,Chandler 会给 Joey 一个数组 a 1 , a 2 , … , a n ( n ≥ 2 , a i ∈ Z + ) a_1,a_2,\dots,a_n(n\ge 2,a_i \in \mathbb{Z^+}) a1,a2,,an(n2,aiZ+)。Joey 可以对这个数组进行如下的操作任意次:

  1. 选择一对 $ i $ 和 $ j $ ( $ 1 \le i < j \le n) $ .
  2. 选择两个整数 $ x $ 和 $ y $ ( $ x, y \ge 1 $ ) 使得 $ x \cdot y = a_i \cdot a_j $ .
  3. a i , a j a_i, a_j ai,aj 分别替换为 x , y x, y x,y.

最后, Joey 将得到的钱就是 a a a 数组中所有值的和。即 Joey 所得的钱 = ∑ i = 1 n a i = \sum^{n}_{i=1}a_{i} =i=1nai .

你需要求出一个整数 a n s ans ans,即 Joey 最多可以得到的钱,并输出 2022 ⋅ a n s 2022 \cdot ans 2022ans 。为什么要乘以 2022 2022 2022 呢?因为我们再也见不到它了!(悲)

输入数据保证 a a a 数组内所有数的乘积不超过 1 0 12 10^{12} 1012,即 ∏ i = 1 n a i ≤ 1 0 12 \prod^{n}_{i=1}a_{i} \le 10^{12} i=1nai1012.

输入格式

输入包含多组测试数据。

  • 第一行,一个整数 T T T,代表测试数据组数。
  • 对于每一组测试数据,第一行为一个整数 n ( 2 ≤ n ≤ 50 ) n(2 \leq n \leq 50) n(2n50),表示数组 a a a 的长度。第二行为 n n n 个整数 a 1 , a 2 , … , a n ( 1 ≤ a i ≤ 1 0 6 ) a_1,a_2,\dots,a_n( 1 \leq a_i \leq 10^6 ) a1,a2,,an(1ai106),表示 a a a 数组。保证 a a a 数组内所有数的乘积不超过 1 0 12 10^{12} 1012,即 ∏ i = 1 n a i ≤ 1 0 12 \prod^{n}_{i=1}a_{i} \le 10^{12} i=1nai1012.

输出格式

共一行,一个整数,表示 Joey 最多可以得到的钱乘以 2022 后的值。

提示

在测试样例的第一组测试数据中,Joey 可以这么做:

  • 他选择 $ i = 1 , j = 2 $ (可得 $ a[i] \cdot a[j] = 6 $ ), 使 $ x = 6, y = 1 $ ,然后改变原数组使 $ a[i] = x = 6 , a[j] = y = 1 $ . 即原数组发生如下变化:
    [ 2 , 3 , 2 ] → x = 6 , y = 1 i = 1 , j = 2 [ 6 , 1 , 2 ] [2, 3, 2] \xrightarrow[x = 6,\; y = 1]{i = 1,\; j = 2} [6, 1, 2] [2,3,2]i=1,j=2 x=6,y=1[6,1,2]
  • 他选择 $i = 1 , j = 3 $ (可得 $ a[i] \cdot a[j] = 12 $ ), 使 $ x = 12 , y = 1 $ 然后改变原数组使 $ a[i] = x = 12 , a[j] = y = 1 $ . 即原数组发生如下变化:
    [ 6 , 1 , 2 ] → x = 12 , ; y = 1 i = 1 , j = 3 [ 12 , 1 , 1 ] [6, 1, 2] \xrightarrow[x = 12,; y = 1]{i = 1,\; j = 3} [12, 1, 1] [6,1,2]i=1,j=3 x=12,;y=1[12,1,1]

综上所述, Joey 可以得到的最多的钱即为 12 + 1 + 1 = 14 12+1+1=14 12+1+1=14 元,所以输出应为 14 × 2022 = 28308 14\times 2022 = 28308 14×2022=28308.

题目描述

Joey is low on money. His friend Chandler wants to lend Joey some money, but can’t give him directly, as Joey is too proud of himself to accept it. So, in order to trick him, Chandler asks Joey to play a game.

In this game, Chandler gives Joey an array $ a_1, a_2, \dots, a_n $ ( $ n \geq 2 $ ) of positive integers ( $ a_i \ge 1 $ ).

Joey can perform the following operation on the array any number of times:

  1. Take two indices $ i $ and $ j $ ( $ 1 \le i < j \le n) $ .
  2. Choose two integers $ x $ and $ y $ ( $ x, y \ge 1 $ ) such that $ x \cdot y = a_i \cdot a_j $ .
  3. Replace $ a_i $ by $ x $ and $ a_j $ by $ y $ .

In the end, Joey will get the money equal to the sum of elements of the final array.

Find the maximum amount of money $ \mathrm{ans} $ Joey can get but print $ 2022 \cdot \mathrm{ans} $ . Why multiplied by $ 2022 $ ? Because we are never gonna see it again!

It is guaranteed that the product of all the elements of the array $ a $ doesn’t exceed $ 10^{12} $ .

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \leq t \leq 4000 $ ). Description of the test cases follows.

The first line of each test case contains a single integer $ n $ ( $ 2 \leq n \leq 50 $ ) — the length of the array $ a $ .

The second line contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 1 \leq a_i \leq 10^6 $ ) — the array itself.

It’s guaranteed that the product of all $ a_i $ doesn’t exceed $ 10^{12} $ (i. e. $ a_1 \cdot a_2 \cdot \ldots \cdot a_n \le 10^{12} $ ).

输出格式

For each test case, print the maximum money Joey can get multiplied by $ 2022 $ .

样例 #1

样例输入 #1

3
3
2 3 2
2
1 3
3
1000000 1000000 1

样例输出 #1

28308
8088
2022000000004044

提示

In the first test case, Joey can do the following:

  1. He chooses $ i = 1 $ and $ j = 2 $ (so he has $ a[i] \cdot a[j] = 6 $ ), chooses $ x = 6 $ and $ y = 1 $ and makes $ a[i] = 6 $ and $ a[j] = 1 $ . $ $KaTeX parse error: Can't use function '$' in math mode at position 66: …= 2} [6, 1, 2] $̲ $ </li><li> He…$.

solution

采用贪心的思想,计算每一个数字的连乘,并放到第一个位置,其他位置为1,此时可以达到最大

//
// Created by Gowi on 2023/12/2.
//#include <iostream>using namespace std;int main() {int t;cin >> t;while (t--) {long long n, s = 1;cin >> n;for (int i = 0; i < n; ++i) {long long a;cin >> a;s *= a;}s = s + n - 1;cout << 2022 * s << endl;}
}

这篇关于Joey Takes Money的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/447225

相关文章

Codeforces Round 946 (Div. 3) E. Money Buys Happiness

m m m个月,每个月月底发 x x x的薪水,也就是第 i i i个月只能用前 i − 1 i-1 i−1个月挣的钱,而不能用这个月挣的钱。第 i i i个月花费 c [ i ] c[i] c[i]的薪水能获得 h [ i ] h[i] h[i]的快乐度,问最多能获取的快乐度是多少。 m m m和 h [ i ] h[i] h[i]都较小 考虑01背包,设 d p [ i ] dp[i] d

【flatbuffer】——TypeError: EndVector() takes 1 positional argument but 2 were given

flatbuffer 版本 1.12.0 描述 采用flatbuffer的python接口进行操作的时候报错 解决 EndVector is a method, so the first parameter is the object itself, and the second parameter is len(buf). Just remove the len(buf) part

NYOJ 588题 Money

以2块钱为例: sum = 1 + 20 / 2 + 20 / 5 +(20 - 5 * 1)/ 2 + (20 - 5 * 2) / 2 + (20 - 5 * 3) / 2 = 29 1.全部是1:1种; 2.全部是2 +  2和1的组合:20 / 2; 3.全部是5 + 5和 1的组合:20 / 5; 4.5,2,1的组合+ 5,2的组合:(20 - 5 * i) / 2,其中,i

c++11 标准模板(STL)本地化库 - 平面类别(std::money_get) - 从输入字符序列中解析并构造货币值

本地化库 本地环境设施包含字符分类和字符串校对、数值、货币及日期/时间格式化和分析,以及消息取得的国际化支持。本地环境设置控制流 I/O 、正则表达式库和 C++ 标准库的其他组件的行为。 平面类别 从输入字符序列中解析并构造货币值 std::money_get template<     class CharT,     class InputIt = std::istream

P1474 货币系统 Money Systems

题目描述 母牛们不但创建了它们自己的政府而且选择了建立了自己的货币系统。由于它们特殊的思考方式,它们对货币的数值感到好奇。 传统地,一个货币系统是由1,5,10,20 或 25,50, 和 100的单位面值组成的。 母牛想知道有多少种不同的方法来用货币系统中的货币来构造一个确定的数值。 举例来说, 使用一个货币系统 {1,2,5,10,…}产生 18单位面值的一些可能的方法是:18x1,

Modeling Maximum Trading Profits with C++: New Trading and Money Management Concepts

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。 http://blog.csdn.net/topmvp - topmvp The goal of trading is to make money, and for many, profits are the best way to measure that success. A

Saving Time and Money Using SAS

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。 http://blog.csdn.net/topmvp - topmvp Get the most from your SAS software! In this expert collection of strategic and tactical solutions, autho

money的工具类

import java.math.BigDecimal;public class NumberUtil {//默认除法运算精度 private static final int DEF_DIV_SCALE = 10; //这个类不能实例化 private NumberUtil(){ } /** * 提供精确的加法运算。 * @para

risky to save money in bank

http://news.sina.com.cn/s/2006-05-25/13319025158s.shtml 500元存30年 利息仅涨百余元

小程序如何帮我们快速的赚money?

目录 前言 1.小程序能为商家带来什么? 2.小程序怎么帮商家引流,具体怎么推广? 3.做小程序可以保证销售额吗? 前言 微信实现“商品搜索”, 即用户在“搜一搜”中输入商品关键词,搜索列表 会直接呈现所有以小程序为载体的商品结果,而每一个搜索结果都可以直接调转 到小程序商品详情页。 憋了 大招终于来了!微信电商逻辑终将被重构! 如果你看不透微信到底要