zoukankan      html  css  js  c++  java
  • 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);
        }
    }
  • 相关阅读:
    python 类定义 继承
    BAYSY2 的LVDS引脚 笔记
    Fedora20-32bit cross-compiling arm-linux-gcc4.3.2
    以冒泡排序为例--malloc/free 重定向stdin stdout
    笔记:程序内存管理 .bss .data .rodata .text stack heap
    第一章 数值和码制
    《将博客搬至CSDN》
    Servlet 3.0 新特性
    java Servlet接口及应用
    C语言输出单个汉字字符
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12375341.html
Copyright © 2011-2022 走看看