D - Three Integers
思路:枚举,还是枚举,走完所有的数字,最后找到最小的,然后输出。
代码:
#include <iostream> #include<algorithm> #include<string> #include<math.h> using namespace std; const int inf = 0x3f3f3f3f; int main() { int t, a, b, c, x, y, z, cnt, sum; scanf("%d", &t); while (t--) { cin >> a >> b >> c; cnt = inf; for (int i = 1; i <= 20000; i++) { for (int j = 1; j*i <= 20000; j++) { for (int k = 1; i*j*k <= 20000; k++) { sum = abs(i-a) + abs(j*i - b) + abs(i*j*k - c); if (cnt>sum) { cnt = sum; x = i; y = i*j; z = i*j*k; } } } } printf("%d\n", cnt); printf("%d %d %d\n", x, y, z); } return 0; }