zcmimi's blog
avatar
zc
2020-05-03 01:04:00
  • 本文总阅读量
查看原题

点击跳转

暴力枚举即可

#include<bits/stdc++.h>
int abs(int x){return x<0?-x:x;}
void solve(){
    int a,b,c,ans=1<<30,lim,res,A,B,C;
    scanf("%d%d%d",&a,&b,&c);lim=c<<1;
    for(int i=1;i<=lim;++i)
        for(int j=i;j<=lim;j+=i)
            for(int k=j;k<=lim;k+=j){
                res=abs(a-i)+abs(b-j)+abs(c-k);
                if(res<ans)ans=res,A=i,B=j,C=k;
            }
    printf("%d\n%d %d %d\n",ans,A,B,C);
}
int main(){
    int t;scanf("%d",&t);
    while(t--)solve();
}
LG CF1311D Three Integers
comment评论
Search
search