博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #624D. Three Integers(思维+暴力枚举)
阅读量:3952 次
发布时间:2019-05-24

本文共 2245 字,大约阅读时间需要 7 分钟。

D. Three Integers

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given three integers a≤b≤ca≤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 A≤B≤CA≤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 (1≤t≤1001≤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 (1≤a≤b≤c≤1041≤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 A≤B≤CA≤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

Copy

81 2 3123 321 4565 10 1515 18 21100 100 1011 22 293 19 386 30 46

output

Copy

11 1 3102114 228 45644 8 16618 18 181100 100 10071 22 2221 19 3886 24 48

【题意】

对于给定的三个数a,b,c,可以进行+1或者-1操作,最后要满足b=k1*a,c=k2*b=k1*k2*a,求满足这个要求所需要的最小操作数,就是枚举的数与a,b,c的差值最小。

因为数据给了1e4,所以直接暴力三层循环枚举,按照倍数枚举,最后复杂度不会是O(n^3),a枚举到10000,b枚举到20000,一般不会超过这个。

#include 
using namespace std;const int inf=0x3f3f3f3f;int main(){ ios::sync_with_stdio(false); int t,a,b,c; int x,y,z; cin>>t; while(t--) { cin>>a>>b>>c; int ans=inf; for(int i=1;i<=10000;i++) { for(int j=1;j*i<=20000;j++) { for(int k=1;i*j*k<=20000;k++) { int sum=abs(a-i)+abs(j*i-b)+abs(i*j*k-c); if(ans>sum) { ans=sum; x=i; y=i*j; z=i*j*k; } } } } cout<
<

 

转载地址:http://ztyzi.baihongyu.com/

你可能感兴趣的文章
在Redhat9下静态编译glib库.
查看>>
CImg库编译使用.
查看>>
SQL Server循环执行动态SQL语句.
查看>>
ubuntu10.4网卡名由eth0改为eth4,导致获得不了IP地址.解决方法.
查看>>
CheckPoint关键词做字段名使用.
查看>>
Qt QSplitte分割器使用(用户手动改变窗口大小)
查看>>
Qt动态加载动态库
查看>>
java8新特性
查看>>
git clone时RPC failed; curl 18 transfer closed with outstanding read data remaining
查看>>
Java8内存模型—永久代(PermGen)和元空间(Metaspace)
查看>>
maven中jar、war、pom的区别
查看>>
maven之pom.xml配置文件详解
查看>>
java基础学习之抽象类与接口的区别
查看>>
java基础学习之包、类、方法、属性、常量的命名规则
查看>>
java基础知识学习之匿名内部类
查看>>
SSM框架和SSH框架的区别
查看>>
Elasticsearch-基础介绍及索引原理分析
查看>>
过滤敏感词算法
查看>>
linux学习之shell脚本if判断参数-n,-d,-f等
查看>>
linux学习之windos文件在linux里面乱码解决
查看>>