当前位置: 首页 > news >正文

洛谷题解 | CF1979C Earning on Bets

目录

    • 题目描述
    • 输入格式
    • 输出格式
    • 输入输出样例 #1
      • 输入 #1
      • 输出 #1
    • 说明/提示
    • 题目思路
    • AC 代码

题目描述

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 $ k_i $ . 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.

输入格式

Each test consists of multiple test cases. The first line contains a single integer $ t $ ( $ 1 \le t \le 10^4 $ ) — 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 \le n \le 50 $ ) — the number of outcomes.

The second line of each test case contains $ n $ integers $ k_1,k_2,\ldots,k_n $ ( $ 2 \le k_i \le 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 \cdot 10^5 $ .

输出格式

For each test case, output $ -1 $ if there is no way to distribute the coins as required. Otherwise, output $ n $ integers $ x_1, x_2,\ldots, x_n $ ( $ 1 \le x_i \le 10^{9} $ ) — 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.

输入输出样例 #1

输入 #1

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

输出 #1

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

说明/提示

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

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

题目思路

猜结论。

k 1 , k 2 , … , k n , k n k_1,k_2,\dots,k_n,k_n k1,k2,,kn,kn,求最小公倍数,设此值为 x x x,则累加 x x x 分别除以 k 1 , k 2 , … , k n k_1,k_2,\dots,k_n k1,k2,,kn 的和,如果此值大于 x x x,则无解。否则,给第每个位置分配 x k i \frac{x}{k_i} kix 数量的钱即可。

AC 代码

#include <bits/stdc++.h>
using namespace std;
long long a[55];
long long gcd(long long a,long long b){if(b == 0) return a;return gcd(b,a % b); 
}
long long lcm(long long a,long long b){return a * b / gcd(a,b);
} 
void solve(){int n;cin >> n;bool ok = 0;long long g = 0,sum = 0;cin >> a[1];g = a[1];for(int i = 2;i <= n;i++){cin >> a[i];g = lcm(g,a[i]);}for(int i = 1;i <= n;i++){sum += g / a[i];}for(int i = 1;i <= n;i++){if(g <= sum){cout << -1;ok = 1;break;}}if(!ok){for(int i = 1;i <= n;i++){cout << g / a[i] << " ";}}cout << endl;
}
int main(){int t;cin >> t; while(t--){solve();}return 0;
} 

创作不易,白嫖不好,各位的支持和认可,就是我创作的最大动力,如果喜欢我的文章,给个关注吧!

冰焰狼 | 文

如果本篇博客有任何错误,请批评指教,不胜感激 !

相关文章:

  • <Revit二次开发> 通过一组模型线构成墙面,并生成墙。Create(Document, IList.Curve., Boolean)
  • 以梦为舟,驶向中医传承新蓝海
  • 宾馆一次性拖鞋很重要,扬州卓韵酒店用品详细介绍其材质与卫生标准
  • Windows 系统下使用 Docker 搭建Redis 集群(6 节点,带密码)
  • (计数)洛谷 P8386 PA2021 Od deski do deski/P10375 AHOI2024 计数 题解
  • Java项目中使用minio存储服务
  • softlockup_panic=1配置方法及区别
  • 基于论文的大模型应用:基于SmartETL的arXiv论文数据接入与预处理(四)
  • 常见的 CSS 知识点整理
  • 实验七:基于89C51和DS18B20的温度采集与显示
  • 源码角度分析 sync.map
  • C++智能指针滥用带来的性能与内存问题有哪些
  • 阿里云bgp服务器优势有哪些?搭建bgp服务器怎么做?
  • Mangodb基本概念和介绍,Mango三个重要的概念:数据库,集合,文档
  • Python在自动驾驶仿真环境中的应用:构建智能驾驶的虚拟世界
  • MySQL基础关键_001_认识
  • 判断图片url损坏无法展示工具类
  • WEB漏洞--CSRF及SSRF案例
  • UNIAPP项目记录
  • Transformer-LSTM-SVM回归
  • 匈牙利国会通过退出国际刑事法院的决定
  • 人社部:将制定提前领取个人养老金相关办法
  • 以“最美通缉犯”为噱头直播?光明网:违法犯罪不应成网红跳板
  • 苏州一季度GDP为6095.68亿元,同比增长6%
  • 俄罗斯总统普京:5月8日零时至11日零时实施停火
  • 北上广深还是小城之春?“五一”想好去哪玩了吗