枚举。每种饲料的份数取值为(0 sim 100),时间复杂度为(O(101^3))。
int g[3];
int a[3][3];
int main()
{
for(int i = 0; i < 3; i++) cin >> g[i];
if(g[0] + g[1] + g[2] == 0) puts("0 0 0 0");
else
{
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
cin >> a[i][j];
int sum = 301;
int ans[4] = {0};
for(int i = 0; i <= 100; i++)
for(int j = 0; j <= 100; j++)
for(int k = 0; k <= 100; k++)
{
if(i + j + k == 0) continue;
int s[3] = {0};
for(int l = 0; l < 3; l++)
s[l] = i * a[0][l] + j * a[1][l] + k * a[2][l];
int t = (s[0] + s[1] + s[2]) / (g[0] + g[1] + g[2]);
if(s[0] == t * g[0] && s[1] == t * g[1] && s[2] == t * g[2] && i + j + k < sum)
{
sum = i + j + k;
ans[0] = i, ans[1] = j, ans[2] = k, ans[3] = t;
}
}
if(sum > 300) puts("NONE");
else
{
for(int i = 0; i < 4; i++)
cout << ans[i] << ' ';
cout << endl;
}
}
}