Check the data range ~~ Up to 100... think about it... all the results obtained by the answer must be smaller than 100... so the three-layer for loop to brute force find the optimal solution to meet the requirements is OK .. it's disgusting .. the given (x, y, z) may have 0... so special processing...
Program:
/*
ID: zzyzzy12
LANG: C ++
TASK: ratios
*/
# Include <iostream>
# Include <istream>
# Include <stdio. h>
# Include <string. h>
# Include <math. h>
# Include <stack>
# Include <algorithm>
# Include <queue>
# Define OOS 2000000000
# Define ll long
Using namespace std;
Struct node
{
Int x, y, z;
} S [4];
Int I, j, k, ans [4], m;
Void getanswer ()
{
Ans [0] = oo;
For (I = 0; I <= 100; I ++)
For (j = 0; j <= 100; j ++)
For (k = 0; k <= 100; k ++)
If ((! S [0]. x | (s [1]. x * I + s [2]. x * j + s [3]. x * k) % s [0]. x = 0 )&&(! S [0]. y | (s [1]. y * I + s [2]. y * j + s [3]. y * k) % s [0]. y = 0 )&&(! S [0]. z | (s [1]. z * I + s [2]. z * j + s [3]. z * k) % s [0]. z = 0 ))
{
M = 0;
If (s [0]. x) m = (s [1]. x * I + s [2]. x * j + s [3]. x * k)/s [0]. x;
Else
{
If (s [1]. x * I + s [2]. x * j + s [3]. x * k) continue;
If (s [0]. y) m = (s [1]. y * I + s [2]. y * j + s [3]. y * k)/s [0]. y;
Else
{
If (s [1]. y * I + s [2]. y * j + s [3]. y * k) continue;
If (s [0]. z) m = (s [1]. z * I + s [2]. z * j + s [3]. z * k)/s [0]. z;
}
}
If (! M) continue;
If (s [1]. y * I + s [2]. y * j + s [3]. y * k = m * s [0]. y)
If (s [1]. z * I + s [2]. z * j + s [3]. z * k = m * s [0]. z)
If (ans [0]> m)
{
Ans [1] = I; ans [2] = j; ans [3] = k;
Ans [0] = m;
}
}
}
Int main ()
{
Freopen ("ratios. in", "r", stdin );
Freopen ("ratios. out", "w", stdout );
For (I = 0; I <4; I ++) scanf ("% d", & s [I]. x, & s [I]. y, & s [I]. z );
Getanswer ();
If (ans [0] = oo) printf ("NONE \ n"); else
Printf ("% d \ n", ans [1], ans [2], ans [3], ans [0]);
Return 0;
}
/*
ID: zzyzzy12
LANG: C ++
TASK: ratios
*/
# Include <iostream>
# Include <istream>
# Include <stdio. h>
# Include <string. h>
# Include <math. h>
# Include <stack>
# Include <algorithm>
# Include <queue>
# Define OOS 2000000000
# Define ll long
Using namespace std;
Struct node
{
Int x, y, z;
} S [4];
Int I, j, k, ans [4], m;
Void getanswer ()
{
Ans [0] = oo;
For (I = 0; I <= 100; I ++)
For (j = 0; j <= 100; j ++)
For (k = 0; k <= 100; k ++)
If ((! S [0]. x | (s [1]. x * I + s [2]. x * j + s [3]. x * k) % s [0]. x = 0 )&&(! S [0]. y | (s [1]. y * I + s [2]. y * j + s [3]. y * k) % s [0]. y = 0 )&&(! S [0]. z | (s [1]. z * I + s [2]. z * j + s [3]. z * k) % s [0]. z = 0 ))
{
M = 0;
If (s [0]. x) m = (s [1]. x * I + s [2]. x * j + s [3]. x * k)/s [0]. x;
Else
{
If (s [1]. x * I + s [2]. x * j + s [3]. x * k) continue;
If (s [0]. y) m = (s [1]. y * I + s [2]. y * j + s [3]. y * k)/s [0]. y;
Else
{
If (s [1]. y * I + s [2]. y * j + s [3]. y * k) continue;
If (s [0]. z) m = (s [1]. z * I + s [2]. z * j + s [3]. z * k)/s [0]. z;
}
}
If (! M) continue;
If (s [1]. y * I + s [2]. y * j + s [3]. y * k = m * s [0]. y)
If (s [1]. z * I + s [2]. z * j + s [3]. z * k = m * s [0]. z)
If (ans [0]> m)
{
Ans [1] = I; ans [2] = j; ans [3] = k;
Ans [0] = m;
}
}
}
Int main ()
{
Freopen ("ratios. in", "r", stdin );
Freopen ("ratios. out", "w", stdout );
For (I = 0; I <4; I ++) scanf ("% d", & s [I]. x, & s [I]. y, & s [I]. z );
Getanswer ();
If (ans [0] = oo) printf ("NONE \ n"); else
Printf ("% d \ n", ans [1], ans [2], ans [3], ans [0]);
Return 0;
}
From Jacob's zone