Codeforces Round #624 (Div. 3)

D - Three Integers
题意:
t组样例每组输入a,b,c;你可以任意给某个数+1 或-1记为一次操作,求满足b能被a整除,c能被b整除的条件下,操作次数最少。
思路:
暴力出奇迹,打表过样例~,这道题直接暴力就能过。

#include
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;
const int N=10500;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;cin>>T;
	while(T--){
		int a,b,c;
		cin>>a>>b>>c;
		int A,B,C,ans=INF;
		for(int i=1;i<=N;i++){
			for(int j=i;j<=N;j+=i){
				for(int k=j;k<=N;k+=j){
					int t=abs(i-a)+abs(j-b)+abs(k-c);
					if(t<ans){
						ans=t;
						A=i;B=j;C=k;
					}
				}
			} 
		}
		cout<<ans<<"\n"<<A<<" "<<B<<" "<<C<<'\n';
	}
	return 0;
}

你可能感兴趣的:(codeforces,暴力)