问题 B: Scaling Recipe

简介: 你有一个食谱,其中指定了一些食材,你需要的每种食材的数量,以及它产生的分量。但是,你需要的份量和食谱中指定的份量不一样!你如何衡量它?

题目描述


You’ve got a recipe which specifies a number of ingredients, the amount of each ingredient you will need, and the number of portions it produces. But, the number of portions you need is not the same as the number of portions specified in the recipe! How can you scale it?


翻译


你有一个食谱,其中指定了一些食材,你需要的每种食材的数量,以及它产生的分量。但是,你需要的份量和食谱中指定的份量不一样!你如何衡量它?


输入


The first line of input contains three integers n (1 ≤ n ≤ 40), x and y (1 ≤ x, y ≤ 40,000), where n is the number of ingredients in the recipe, x is the number of portions that the recipe produces, and y is the number of portions you need. Each of the next n lines contains a single integer a (1 ≤ a ≤ 40,000). These are the amounts of each ingredient needed for the recipe. The inputs will be chosen so that the amount of each ingredient needed for y portions will be an integer.


翻译


输入的第一行包含三个整数n(1≤n≤40),x和y(1≤x, y≤40000),其中n是配方成分的数量,x是部分配方生产的数量,和y是部分你需要的数量。后面的每n行包含一个整数a(1≤a≤40000)。这是食谱中每种原料的用量。将选择输入,以便y部分所需的每个成分的数量将是一个整数。


输出


Output n lines. On each line output a single integer, which is the amount of that ingredient needed to produce y portions of the recipe. Output these values in the order of the input.


翻译

输出n行。在每一行上输出一个整数,这是生成recipe的y部分所需的配料的数量。按输入的顺序输出这些值。

PS:关键点,等比例缩放,并且数值不能爆炸

代码:

#include<iostream>
using namespace std;
int gcd(int m, int n) {//求公因数函数
  while (m != n) {
    if (m > n)
      m = m - n;
    else
      n = n - m;
  }
  return n;
}
int main()
{
  int n, x, y, a, t;
  cin >> n >> x >> y;
  t = gcd(x, y);
  x = x / t;
  y = y / t;
  for (int i = 0; i < n; i++) {
    cin >> a;
    int z = gcd(x, a), temp;
    a = a / z;
    temp = x / z;
    cout << (y * a) / temp << endl;
  }
  return 0;
}
相关文章
|
弹性计算 安全 容灾
【深度好文】为什么说用好VPC很重要!
本文详细探讨了阿里云VPC(Virtual Private Cloud)的使用方法及其重要性。 VPC作为用户云上的“数据中心”,提供了安全隔离的网络环境,帮助用户构建和管理云服务。文章首先对比了经典网络和VPC的区别,强调了VPC在安全性、灵活性和扩展性方面的优势。接着,通过具体的规划步骤,包括选择地域、账号规划、网段规划、安全隔离设计等,展示了如何有效利用VPC。此外,还介绍了VPC连接互联网的方式及安全措施,以及VPC与IDC互访的解决方案。 总体而言,VPC不仅是用户上云的第一步,更是构建稳定、高效云基础设施的关键。
|
中间件 测试技术 持续交付
FastAPI测试秘籍:如何通过细致的测试策略确保你的代码在真实世界的挑战面前保持正确和稳定?
【8月更文挑战第31天】在软件开发中,测试至关重要,尤其在动态语言如Python中。FastAPI不仅简化了Web应用开发,还提供了强大的测试工具。通过`unittest`框架和Starlette测试客户端,开发者可以轻松编写和执行测试用例,确保每个功能按预期工作。本文将详细介绍如何设置测试环境、编写基础和高级测试用例,并探讨中间件和依赖项测试。此外,还将介绍如何在持续集成环境中自动化测试,确保代码质量和稳定性。利用FastAPI的测试工具,你可以构建出高效可靠的Web应用。
248 0
|
Linux Shell Python
vscode运行Python的两种方法,及无法运行的原因
下面介绍的vscode运行Python代码的方法基于的一个前提条件是:当前的计算机已经安装好了Python,且已经配置好了相关的环境变量。如果要查看是否已经都安装好了,可以打开Windows系统的命令行工具Windows PowerShell,如果是Mac系统或Linux系统,则可以打开终端,然后键入命令:python,如果
855 3
|
安全 数据安全/隐私保护
windows10 查看已连接wifi的密码
windows10 查看已连接wifi的密码
585 0
|
机器学习/深度学习
大模型中的Scaling Law是什么?
【2月更文挑战第9天】大模型中的Scaling Law是什么?
17703 3
大模型中的Scaling Law是什么?
|
JavaScript 前端开发 Java
打造高效对象:编程秘籍与代码实操
打造高效对象:编程秘籍与代码实操
86 0
如何设置kibana界面语言
如何设置kibana界面语言
909 0
如何获取 kaggle 用户的用户名和API密钥(key)
如何获取 kaggle 用户的用户名和API密钥(key)
1001 0
|
TensorFlow 算法框架/工具 Python
tensorflow安装错误:Could not find a version that satisfies the requirement tensorflow 解决
tensorflow安装错误:Could not find a version that satisfies the requirement tensorflow 解决
|
传感器 运维 负载均衡
Dubbo了解一下
Apache Dubbo是阿里巴巴开源的一款高性能、轻量级的开源Java RPC框架,它提供了三大核心能力:面向接口的远程方法调用,智能容错和负载均衡,以及服务自动注册和发现。
190 0
Dubbo了解一下