问题 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;
}
目录
打赏
0
0
0
0
0
分享
相关文章
【深度好文】为什么说用好VPC很重要!
本文详细探讨了阿里云VPC(Virtual Private Cloud)的使用方法及其重要性。 VPC作为用户云上的“数据中心”,提供了安全隔离的网络环境,帮助用户构建和管理云服务。文章首先对比了经典网络和VPC的区别,强调了VPC在安全性、灵活性和扩展性方面的优势。接着,通过具体的规划步骤,包括选择地域、账号规划、网段规划、安全隔离设计等,展示了如何有效利用VPC。此外,还介绍了VPC连接互联网的方式及安全措施,以及VPC与IDC互访的解决方案。 总体而言,VPC不仅是用户上云的第一步,更是构建稳定、高效云基础设施的关键。
FastAPI测试秘籍:如何通过细致的测试策略确保你的代码在真实世界的挑战面前保持正确和稳定?
【8月更文挑战第31天】在软件开发中,测试至关重要,尤其在动态语言如Python中。FastAPI不仅简化了Web应用开发,还提供了强大的测试工具。通过`unittest`框架和Starlette测试客户端,开发者可以轻松编写和执行测试用例,确保每个功能按预期工作。本文将详细介绍如何设置测试环境、编写基础和高级测试用例,并探讨中间件和依赖项测试。此外,还将介绍如何在持续集成环境中自动化测试,确保代码质量和稳定性。利用FastAPI的测试工具,你可以构建出高效可靠的Web应用。
164 0
大模型中的Scaling Law是什么?
【2月更文挑战第9天】大模型中的Scaling Law是什么?
15976 3
大模型中的Scaling Law是什么?
如何获取 kaggle 用户的用户名和API密钥(key)
如何获取 kaggle 用户的用户名和API密钥(key)
759 0
Dubbo了解一下
Apache Dubbo是阿里巴巴开源的一款高性能、轻量级的开源Java RPC框架,它提供了三大核心能力:面向接口的远程方法调用,智能容错和负载均衡,以及服务自动注册和发现。
164 0
Dubbo了解一下
移动端IM产品RainbowChat[专业版] iOS端 v6.0版已发布!
RainbowChat是一套基于开源IM聊天框架 MobileIMSDK 的产品级移动端IM系统。RainbowChat源于真实运营的产品,解决了大量的屏幕适配、细节优化、机器兼容问题(可自行下载体验:专业版下载安装)。 * RainbowChat可能是市面上提供im即时通讯聊天源码的,唯一一款同时支持TCP、UDP两种通信协议的IM产品(通信层基于开源IM聊天框架 MobileIMSDK 实现)。
205 0
移动端IM产品RainbowChat[专业版] iOS端 v6.0版已发布!
Seata Transaction Coordinator
前面,我们已经介绍了 Seata 的整体设计思想,接下来我们深入到其实现细节中,本文介绍 Seata 中最核心的模块 Transaction Coordinator 的实现。
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问