问题 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;
}
相关文章
|
3月前
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
46 5
|
算法
【5分钟 Paper】Deterministic Policy Gradient Algorithms
【5分钟 Paper】Deterministic Policy Gradient Algorithms
|
算法 计算机视觉 知识图谱
ACL2022:A Simple yet Effective Relation Information Guided Approach for Few-Shot Relation Extraction
少样本关系提取旨在通过在每个关系中使用几个标记的例子进行训练来预测句子中一对实体的关系。最近的一些工作引入了关系信息
104 0
|
12月前
|
算法 Linux Shell
SGAT丨Single Gene Analysis Tool
SGAT丨Single Gene Analysis Tool
|
人工智能 数据可视化 决策智能
【CAMEL】Communicative Agents for “Mind”Exploration of Large Scale Language Model Society
【CAMEL】Communicative Agents for “Mind”Exploration of Large Scale Language Model Society
313 0
|
机器学习/深度学习 自然语言处理 算法
Joint Information Extraction with Cross-Task and Cross-Instance High-Order Modeling 论文解读
先前的信息抽取(IE)工作通常独立地预测不同的任务和实例(例如,事件触发词、实体、角色、关系),而忽略了它们的相互作用,导致模型效率低下。
77 0
|
机器学习/深度学习 存储 传感器
Automated defect inspection system for metal surfaces based on deep learning and data augmentation
简述:卷积变分自动编码器(CVAE)生成特定的图像,再使用基于深度CNN的缺陷分类算法进行分类。在生成足够的数据来训练基于深度学习的分类模型之后,使用生成的数据来训练分类模型。
136 0
|
算法 关系型数据库 MySQL
Fundamental Techniques for Order Optimization
这是一篇1996年的老paper了,主要讲解了IBM DB2如何针对query当中的有序性进行优化。但对于后续physical property的优化有较为深远的影响,由于DB2的优化器起源于System-R以及其后续演进的starburst,因此延续了system-R中的interesting order和order property的概念。关于system-R的介绍请看之前的文章。 order这种physical property并不只限于order by算子,基于有序的group by/distinct等,都会利用到数据的排序操作,而排序本身就是比较昂贵的计算,因此应该对其做尽可能的优化
206 0
Fundamental Techniques for Order Optimization
|
机器学习/深度学习 自然语言处理 算法
《Semi-supervised Collaborative Filtering by Text-enhanced Domain Adaptation》解读
推荐算法是机器学习的一个重要应用,推荐算法与其他机器学习算法的一个重要区别在于数据的特点。在推荐系统中,由于用户行为的长尾效应,往往数据极为稀疏,而另一个问题在于,推荐算法的数据集往往是隐式反馈,即通过对用户行为的采集而非query来获得用户对推荐标的的反馈。学界针对这两个问题曾提出过不少方法,也有很多经典的工作。然而,这两个问题始终没有得到完整的解决。
《Semi-supervised Collaborative Filtering by Text-enhanced Domain Adaptation》解读