• Codeforces Round #624 (Div. 3) D. Three Integers


    You are given three integers abca≤b≤c .

    In one move, you can add +1+1 or 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 ABCA≤B≤C such that BB is divisible by AA and CC is divisible by BB .

    You have to answer tt independent test cases.

    Input

    The first line of the input contains one integer tt (1t1001≤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 (1abc1041≤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 ABCA≤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
     
    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
     
    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
    一开始想了半天再加上题目的rating1900+math的标签就以为是数论不敢做了,后来看大佬说是暴力...枚举有两种方式,一种是直接枚举A,B,C(注意里面两重循环 for(int j = i; j <= 15000; j += i)for(int k = j; k <= 15000; k += j)不要写++;一种是枚举倍数 for(k=1;i*j*k<=20000;k++)for(k=1;i*j*k<=20000;k++)。玄学范围看着枚举就行,看似O(n^3)实际上有了剪枝是到不了的。Div3别想的太复杂。
    #include <bits/stdc++.h>
    int a,b,c;
    using namespace std;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            scanf("%d%d%d",&a,&b,&c);
            int A,B,C,i,j,k;
            
            int mmin=99999999;
            int tot;
            for(i=1;i<=10000;i++)
            {
                for(j=1;i*j<=20000;j++)
                {
                    for(k=1;i*j*k<=20000;k++)
                    {
                        tot=abs(a-i)+abs(b-j*i)+abs(c-i*j*k);
                        if(tot<mmin)
                        {
                            mmin=tot;
                            A=i;
                            B=i*j;
                            C=i*j*k;
                        }
                    }
                }
            }
            cout<<mmin<<endl;
            printf("%d %d %d
    ",A,B,C);
        }
    }
  • 相关阅读:
    使用ltp4j碰到Can't find dependent libraries报错信息的问题解决
    记录遭遇挖矿程序kthrotlds的失败处理经历
    腾讯云短信服务的申请和验证使用详细流程
    再谈腾讯云centos服务器不能登录的解决过程
    腾讯云centos服务器不能登录的解决过程
    解决tomcat部署项目中碰到的几个问题
    设计模式之二——从江湖情报变动通知各门派看观察者模式
    web.xml配置详解
    pom.xml详解
    mysql workbench EER model 乱码
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12375341.html
Copyright © 2020-2023  润新知