Codeforces Round 951 (Div. 2) C题题解

 

C. Earning on Bets

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You have been offered to play a game. In this game, there are n� possible outcomes, and for each of them, you must bet a certain integer amount of coins. In the event that the i�-th outcome turns out to be winning, you will receive back the amount of coins equal to your bet on that outcome, multiplied by ki��. Note that exactly one of the n� outcomes will be winning.

Your task is to determine how to distribute the coins in such a way that you will come out ahead in the event of any winning outcome. More formally, the total amount of coins you bet on all outcomes must be strictly less than the number of coins received back for each possible winning outcome.

DeepL 翻译

有人提议让您玩一个游戏。在这个游戏中,有 n� 种可能的结果,对于每一种结果,您都必须下注一定整数的硬币。如果 i� ()的结果是赢的,您将获得与您在该结果上的赌注相等的硬币金额乘以 ki�� 。请注意, n� 个结果中只有**个结果是赢的。

你的任务是决定如何分配硬币,以便在出现任何*中奖结果时都能获胜。更正式地说,你在所有结果上投注的硬币总数必须严格地小于每个可能获胜的结果所得到的硬币数量。

Input

Each test consists of multiple test cases. The first line contains a single integer t� (1≤t≤1041≤�≤104) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n� (1≤n≤501≤�≤50) — the number of outcomes.

The second line of each test case contains n� integers k1,k2,…,kn�1,�2,…,�� (2≤ki≤202≤��≤20) — the multiplier for the amount of coins if the i�-th outcome turns out to be winning.

It is guaranteed that the sum of n� over all test cases does not exceed 2⋅1052⋅105.

DeepL 翻译

输入

每个测试由多个测试用例组成。第一行包含一个整数 t� ( 1≤t≤1041≤�≤104 ) - 测试用例的数量。测试用例说明如下。

每个测试用例的第一行包含一个整数 n� ( 1≤n≤501≤�≤50 ) - 结果数。

每个测试用例的第二行包含 n� 个整数 k1,k2,…,kn�1,�2,…,�� ( 2≤ki≤202≤��≤20 ) - 如果 i� -th 的结果是中奖,则硬币数量的乘数。

保证所有测试案例中 n� 的总和不超过 2⋅1052⋅105 。

Output

For each test case, output −1−1 if there is no way to distribute the coins as required. Otherwise, output n� integers x1,x2,…,xn�1,�2,…,�� (1≤xi≤1091≤��≤109) — your bets on the outcomes.

It can be shown that if a solution exists, there is always a solution that satisfies these constraints.

If there are multiple suitable solutions, output any of them.

DeepL 翻译

输出

对于每个测试用例,如果无法按要求分配硬币,则输出 −1−1 。否则,输出 n� 个整数 x1,x2,…,xn�1,�2,…,�� ( 1≤xi≤1091≤��≤109 ) - 您对结果的赌注。

可以证明,如果存在一个解,那么总有一个解满足这些约束条件。

如果有多个合适的解,则输出其中任何一个。

Example

input

Copy

 

6

3

3 2 7

2

3 3

5

5 5 5 5 5

6

7 9 3 17 9 13

3

6 3 2

5

9 4 6 8 3

output

Copy

27 41 12 
1 1 
-1
1989 1547 4641 819 1547 1071 
-1
8 18 12 9 24

Note

In the first test case, the coins can be distributed as follows: 2727 coins on the first outcome, 4141 coins on the second outcome, 1212 coins on the third outcome. Then the total amount of coins bet on all outcomes is 27+41+12=8027+41+12=80 coins. If the first outcome turns out to be winning, you will receive back 3⋅27=813⋅27=81 coins, if the second outcome turns out to be winning, you will receive back 2⋅41=822⋅41=82 coins, if the third outcome turns out to be winning, you will receive back 7⋅12=847⋅12=84 coins. All these values are strictly greater than 8080.

In the second test case, one way is to bet one coin on each of the outcomes.

DeepL 翻译

在第一个测试案例中,硬币的分配情况如下: 2727 枚硬币押在第一个结果上, 4141 枚硬币押在第二个结果上, 1212 枚硬币押在第三个结果上。那么在所有结果上投注的硬币总数为 27+41+12=8027+41+12=80 枚。如果第一个结果获胜,您将获得 3⋅27=813⋅27=81 个金币;如果第二个结果获胜,您将获得 2⋅41=822⋅41=82 个金币;如果第三个结果获胜,您将获得 7⋅12=847⋅12=84 个金币。所有这些数值都严格大于 8080 。

在第二个测试案例中,一种方法是在每个结果上都下注一枚硬币。

思路:

结论题,猜出结论就很好求

a1*b1(任意)>b1+b3+b2+b4

每个都要大于总硬币数即求a序列的最小公倍数

来确定b序列,但注意不能大于a序列的最小公倍数

#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
ll gcd(ll a,ll b){
	ll c;
	while(c=a%b){
		a=b;
		b=c;
	}
	return b;
}
ll lcm(ll a,ll b){
	return a*b/gcd(a,b);
}
void slove(){
	int n;cin>>n;
	ll a[n+1];
	long long sum=1;
	long long g=0;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		sum=lcm(sum,a[i]);//求所有数的最小公倍数,如果不成立,则后面所有数都不成立
	}
	for(int i=1;i<=n;++i)g+=sum/a[i];//计算投下硬币数之和
	if(g>=sum)cout<<-1<<endl;//如果投下硬币总数大于硬币总数,则无法成立,否则每种都大于
	else {
		for(int i=1;i<=n;++i)cout<<sum/a[i]<<" \n"[i==n];//输出
	}
}
int main( )
{
    int T;cin>>T;
    while(T--){
       slove();
    }
    return 0;
}

  • 18
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,根据提供的引用内容,我无法理解你具体想要问什么问。请提供更清晰明确的问,我将竭诚为你解答。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [【CodeforcesCodeforces Round 865 (Div. 2) (补赛)](https://blog.csdn.net/t_mod/article/details/130104033)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值