1998 ACM Finals, Dan Adkins
Farmer John feeds his cows only the finest mixture of cow food, which has three components: Barley, Oats, and Wheat. While he knows the precise mixture of these easily mixable grains, he can not buy that mixture! He buys three other mixtures of the three grains and then combines them to form the perfect mixture.
Given a set of integer ratios barley:oats:wheat, find a way to combine them IN INTEGER MULTIPLES to form a mix with some goal ratio x:y:z.
For example, given the goal 3:4:5 and the ratios of three mixtures:
1:2:3 3:7:1 2:1:2
your program should find some minimum number of integer units (the `mixture') of the first, second, and third mixture that should be mixed together to achieve the goal ratio or print `NONE'. `Minimum number' means the sum of the three non-negative mixture integers is minimized.
For this example, you can combine eight units of mixture 1, one unit of mixture 2, and five units of mixture 3 to get seven units of the goal ratio:
8*(1:2:3) + 1*(3:7:1) + 5*(2:1:2) = (21:28:35) = 7*(3:4:5)
Integers in the goal ratio and mixture ratios are all non-negative and smaller than 100 in magnitude. The number of units of each type of feed in the mixture must be less than 100. The mixture ratios are not linear combinations of each other.
PROGRAM NAME: ratios
INPUT FORMAT
Line 1: | Three space separated integers that represent the goal ratios |
Line 2..4: | Each contain three space separated integers that represent the ratios of the three mixtures purchased. |
SAMPLE INPUT (file ratios.in)
3 4 5 1 2 3 3 7 1 2 1 2
OUTPUT FORMAT
The output file should contain one line containing four integers or the word `NONE'. The first three integers should represent the number of units of each mixture to use to obtain the goal ratio. The fourth number should be the multiple of the goal ratio obtained by mixing the initial feed using the first three integers as mixing ratios.
SAMPLE OUTPUT (file ratios.out)
8 1 5 7
题意:
给出 3 个数,还有 3 X 3 的矩阵,可以对每一行乘上一个系数,使最终对应加起来能得到给出的 3 个数,可以提出公因子,输出这 3 个系数和公因子。凑不出则输出 NONE。数据小于100。
思路:
乍一看就想到高斯消元。但是一看数据才小于 100,所以果断暴力了。因为可能会有除 0 的状况,所以每一种情况都讨论了一遍。
AC:
/* ID:sum-g1 LANG:C++ PROG:ratios */ #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; int main() { freopen("ratios.in","r",stdin); freopen("ratios.out","w",stdout); int A, B, C; int num[5][5]; scanf("%d%d%d", &A, &B, &C); for (int i = 1; i <= 3; ++i) for (int j = 1; j <= 3; ++j) scanf("%d", &num[i][j]); int temp = 0; for (int x = 0; x <= 100; ++x) { for (int y = 0; y <= 100; ++y) { for (int z = 0; z <= 100; ++z) { int aa = x * num[1][1] + y * num[2][1] + z * num[3][1]; int bb = x * num[1][2] + y * num[2][2] + z * num[3][2]; int cc = x * num[1][3] + y * num[2][3] + z * num[3][3]; int t1, t2, t3; if (!A && B && C) { if (!bb || !cc || aa) continue; if (bb % B || cc & C) continue; if (bb / B == cc / C) { printf("%d %d %d %d\n", x, y, z, bb / B); temp = 1; break; } } else if (A && !B && C) { if (!aa || bb || !cc) continue; if (aa % A || cc % C) continue; if (aa / A == cc / C) { printf("%d %d %d %d\n", x, y, z, aa / A); temp = 1; break; } } else if (A && B && !C) { if (!aa || !bb || cc) continue; if (aa % A || bb % B) continue; if (aa / A == bb / B) { printf("%d %d %d %d\n", x, y, z, bb / B); temp = 1; break; } } else if (!A && !B && C) { if (aa || bb || !cc) continue; if (cc % C) continue; printf("%d %d %d %d\n", x, y, z, cc / C); temp = 1; break; } else if (!A && B && !C) { if (aa || !bb || cc) continue; if (bb % B) continue; printf("%d %d %d %d\n", x, y, z, bb / B); temp = 1; break; } else if (A && !B && !C) { if (!aa || bb || cc) continue; if (aa % A) continue; printf("%d %d %d %d\n", x, y, z, aa / A); temp = 1; break; } else if (!A && !B && !C) { printf("%d %d %d %d\n", 0, 0, 0, 0); temp = 1; break; } else { if (!aa || !bb || !cc) continue; if (aa % A || bb % B || cc % C) continue; if (aa / A == bb / B && aa / A == cc / C) { printf("%d %d %d %d\n", x, y, z, aa / A); temp = 1; break; } } } if (temp) break; } if (temp) break; } if (!temp) printf("NONE\n"); return 0; }
相关推荐
Financial history and ratios.xls
The Sharpe ratio (Sharpe 1992) is one industry standard for measuring the absolute risk adjusted performance of hedge funds. This function performs the testing of Sharpe ratio difference for two funds...
《测试修改后的夏普比率的平等性》这篇文章探讨了如何评估具有非正态回报的投资的风险调整后表现,特别是在对冲基金领域。夏普比率(Sharpe 1992)是衡量对冲基金绝对风险调整业绩的一个行业标准,而本文提出了一种...
FINANCIAL HISTORY AND RATIOS(表格模板、XLS格式).xls
### 测量加性交互作用使用比值比 #### 概述 本文旨在探讨在流行病学研究中如何准确地衡量两个风险因素之间的加性交互作用,并特别关注使用比值比(Odds Ratio, OR)作为效应度量时的情况。在流行病学中,交互作用...
在深入探讨标题《On some ratios of ergodic sums in continued fractions》和描述中提到的知识点之前,有必要先简单介绍一下连分数。连分数是一种用来表示实数的表达式,它可以无限扩展,并且拥有独特的性质,使其...
关键词中的“高长径比(high aspect ratios)”指的是孔的深度与孔径的比值很大,这在微电子和光电子器件的制造中非常重要。由于高长径比孔具有较大的表面积与体积比,其在功能上具备更高的敏感性和反应性,因此在...
与选定的参考基准相比,向上和... Reference 和 account 可以在同一个输入表中,也可以在具有相同列布局的不同表文件中输入。 很少,这也可能作为一个指标是可取的,为此目的,为两个比率的移动窗口计算添加回顾滞后。
在CFA一级考试中,第八部分“Investment Tools”涵盖了财务报表分析以及财务比率和每股收益(Earnings per Share)等内容。这部分旨在帮助考生评估公司的财务健康状况、运营效率、风险状况以及增长潜力。...
to nonlinear sum-of-ratios problem arising in image processing, engineering and man- agement. Unlike traditional methods which may get trapped in local minima due to the non-convex nature of this ...
标题“SIDM_GC_axis_ratios”暗示我们正在讨论与自交互暗物质(Self-Interacting Dark Matter, SIDM)在球状星团(Globular Clusters, GCs)中的分布和几何特性有关的主题。球状星团是密集的恒星集合,而暗物质是一...
固固比对磷酸镁钾化学结合陶瓷的固化行为及相组成和微观结构的影响,王爱娟,袁志龙,磷酸镁钾化学结合陶瓷已经应用到生物医学领域。在本研究中,了解了不同固固比(即氧化镁:磷酸二氢钾)所形成的化学结合陶瓷的固化...
类铍离子内壳激发态1s2p3 3Po 和 3Do的能量、俄歇宽度和俄歇分支率的计算,张孟,苟秉聪,本文采用鞍点变分方法计算了类铍离子等电子系列(Z=4-10)内壳激发态1s2p3 3Po 和3Do的相对论能量。采用鞍点复数转动方法计算...
### MySQL 分页技术详解 在数据库管理中,对大量数据进行有效的检索与展示是一项重要的任务。MySQL 提供了多种方式来实现数据分页,其中使用 `LIMIT` 语句是最常见的方法之一。此外,还可以通过编写存储过程来实现...
"Feed Ratios"使用了高斯消元法来解决线性方程组问题,"Magic Squares"结合了广度优先搜索(BFS)和哈希表,"Sweet Butter"则涉及到了单源最短路径问题,可以使用SPFA(Shortest Path Faster Algorithm)算法求解。...