当前位置:网站首页>Codeforces Round #624 (Div. 3)
Codeforces Round #624 (Div. 3)
2022-08-02 15:32:00 【A bigot is lovely】
Codeforces Round #624 (Div. 3)
D. Three Integers
You are given three integers a≤b≤c.
In one move, you can add +1 or −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≤C such that B is divisible by A and C is divisible by B.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t(1≤t≤100) — the number of test cases.
The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a,b and c (1≤a≤b≤c≤104).
Output
For each test case, print the answer. In the first line print res— the minimum number of operations you have to perform to obtain three integers A≤B≤C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A,B and C.
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
解析
题目大意就是,给你三个数a,b,c,进行+1或-1操作,使得 b%a== 0&&c%b == 0 ,Find the minimum number of operation.
This topic by ordinary positive thinking will be very complicated,第一个想到的就是bfs,但是用bfs很容易爆内存.
Simple method is to change an idea:从满足b%a== 0&&c%b == 0Conditions began to find the minimum value.
ac代码
#include<bits/stdc++.h>
using namespace std;
int t,a,b,c;
int main()
{
scanf("%d",&t);
while(t--)
{
cin>>a>>b>>c;
int v1=0,v2=0,v3=0,ans=2147483647;
for(int i=1;i<=11000;i++)
for(int j=i;j<=11000;j+=i)
for(int k=j;k<=11000;k+=j)
if(abs(a-i)+abs(b-j)+abs(c-k)<ans)
ans=abs(a-i)+abs(b-j)+abs(c-k),v1=i,v2=j,v3=k;
printf("%d\n",ans);
printf("%d %d %d\n",v1,v2,v3);
}
return 0;
}
边栏推荐
- MATLAB绘制平面填充图入门详解
- 5. Use RecyclerView to elegantly achieve waterfall effect
- Win10 Settings screen out from lack of sleep?Win10 set the method that never sleep
- What are IPV4 and IPV6?
- STM32LL library use - SPI communication
- Win10电脑不能读取U盘怎么办?不识别U盘怎么解决?
- 7.Redis
- Win10系统设置application identity自动提示拒绝访问怎么办
- Win11 computer off for a period of time without operating network how to solve
- Win11没有本地用户和组怎么解决
猜你喜欢

Use tencent cloud builds a personal blog

Introduction to in-order traversal (non-recursive, recursive) after binary tree traversal

CI24R1小模块2.4G收发模块无线通信低成本兼容si24r1/XN297超低功耗

软件测试基础知识(背)

General syntax and usage instructions of SQL (picture and text)

奇技淫巧-位运算

STM32LL库——USART中断接收不定长信息

1.开发社区首页,注册

基于矩阵计算的线性回归分析方程中系数的估计

word方框怎么打勾?
随机推荐
3.用户上传头像
【系统设计与实现】基于flink的分心驾驶预测与数据分析系统
BLE蓝牙5.2-PHY6222系统级芯片(SoC)智能手表/手环
Publish module to NPM should be how to operate?Solutions to problems and mistake
动态规划理论篇
二叉树的遍历:递归法/ 迭代法/ 统一迭代法(强QAQ)
1.开发社区首页,注册
5. Use RecyclerView to elegantly achieve waterfall effect
将SSE指令转换为ARM NEON指令
发布模块到npm应该怎么操作?及错误问题解决方案
7.Redis
Daily - Notes
win10怎么设置不睡眠熄屏?win10设置永不睡眠的方法
win10任务栏不合并图标如何设置
编译error D8021 :无效的数值参数“/Wextra” cl command line error d8021 invalid numeric argument ‘/wextra‘
Mysql connection error solution
专硕与学硕
MATLAB图形加标注的基本方法入门简介
MATLAB绘图函数plot详解
ASR6601牛羊定位器芯片GPS国内首颗支持LoRa的LPWAN SoC