D. Three Integers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given three integers a≤b≤ca≤b≤c.
In one move, you can add +1+1&nbs***bsp;−1−1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations.
You have to perform the minimum number of such operations in order to obtain three integers A≤B≤CA≤B≤C such that BB is divisible by AAand CC is divisible by BB.
You have to answer tt independent test cases.
Input
The first line of the input contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.
The next tt lines describe test cases. Each test case is given on a separate line as three space-separated integers a,ba,b and cc (1≤a≤b≤c≤1041≤a≤b≤c≤104).
Output
For each test case, print the answer. In the first line print resres — the minimum number of operations you have to perform to obtain three integers A≤B≤CA≤B≤C such that BB is divisible by AA and CC is divisible by BB. On the second line print any suitable triple A,BA,B and CC.
Example
input
Copy
8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46
output
Copy
1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48
题意:
给出3个正整数,每次操作只能对某个数+1或-1,问至少操作多少次可以得到A < B < C ,B能被A整除,C能被B整除。
1 <= a, b, c <= 10000, 枚举 + 剪枝
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int N = 2e5 + 10;
int main()
{
int t, a, b, c;
scanf("%d", &t);
while(t--)
{
scanf("%d%d%d", &a, &b, &c);
int ans = inf;
int A, B, C;
for(int i = 1; i <= 15000; ++i)
{
for(int j = i; j <= 15000; j += i)
{
for(int k = j; k <= 15000; k += j)
{
int tmp = abs(a - i) + abs(b - j) + abs(c - k);
if(ans > tmp)
{
ans = tmp;
A = i;
B = j;
C = k;
}
}
}
}
cout<<ans<<'\n';
cout<<A<<' '<<B<<' '<<C<<'\n';
}
return 0;
}