比例混合:
sa, sb, sc分别表示x, y, z 饲料配置总份数
sa = k * x, sb = k * y, sc = k * z;
求k可以相加 $k = \frac {(sa + sb + sc)} {(x + y + z)} $
#include <iostream>
using namespace std;
int main()
{
int g[3];
for (int i = 0; i < 3; i ++) cin >> g[i];
if (g[0] + g[1] + g[2] == 0) puts("0 0 0 0");
else
{
int a[3][3];
for (int i = 0; i < 3; i ++)
for (int j = 0; j < 3; j ++)
cin >> a[i][j];
int res = 301, r[4];
for (int x = 0; x <= 100; x ++)
for (int y = 0; y <= 100; y ++)
for (int z = 0; z <= 100; z ++)
{
if (x + y + z == 0) continue;
int sa = x * a[0][0] + y * a[1][0] + z * a[2][0];
int sb = x * a[0][1] + y * a[1][1] + z * a[2][1];
int sc = x * a[0][2] + y * a[1][2] + z * a[2][2];
int k = (sa + sb + sc) / (g[0] + g[1] + g[2]);
if (g[0] * k == sa && g[1] * k == sb && g[2] * k == sc)
{
if (x + y + z < res)
{
res = x + y + z;
r[0] = x, r[1] = y, r[2] = z, r[3] = k;
}
}
}
if (res <= 300)
for (int i = 0; i < 4; i ++) cout << r[i] << ' ';
else puts("NONE");
}
return 0;
}