题意 :
- 给三个数abc,每次操作可以让其中一个数加一,另一个数减一,问 a b s ( a + c − 2 b ) abs(a+c-2b) abs(a+c−2b)的最小值
思路 :
- 若a+1,c-1,sum不变
- 若a+1,b-1,sum+3
- 若a-1,b+1,sum-3
- 说明有效操作只有+3和-3
- 因此,如果原先sum%3==0,最小值就是0,如果!=0,会变成1或者2,那么绝对值最小值就是1
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int _;
cin >> _;
while (_ -- )
{
int a, b, c;
cin >> a >> b >> c;
cout << (abs(a + c - 2 * b) % 3 ? 1 : 0) << endl;
}
return 0;
}