题解:AT_arc128_b [ARC128B] Balls of Three Colors
我们可以根据样例三来推出一条规律,对
只要三个数模 3 有两个同余,就可以得到答案
那么思路就十分简单了,找余数,再以两个数中的较大数为代价,最后在所有代价中找最小值就可以了。
Code
#include<bits/stdc++.h>
using namespace std;
#define V vector
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int T;
cin>>T;
while(T--){
int r,g,b;
V<int>a(3);
cin>>a[0]>>a[1]>>a[2];
sort(a.begin(),a.end());//规定大小更好判断
r=a[0],g=a[1],b=a[2];
V<int>ans;
int r1=r%3,r2=g%3,r3=b%3;
if(r1==r2) ans.push_back(g);//同余
if(r2==r3) ans.push_back(b);
if(r1==r3) ans.push_back(b);
if(ans.empty()){//无同余
ans.push_back(-1);
}
sort(ans.begin(),ans.end());
cout<<ans[0]<<"\n";
}
return 0;
}
/*
1
1 3 4
*/