当前位置:网站首页>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;
}
边栏推荐
- Mysql的锁
- 将SSE指令转换为ARM NEON指令
- LORA芯片ASR6505无线远距离传输8位MCU
- DP1101兼容CC1101是SUB1GHz无线收发芯片应用于智能家居
- Actual combat Meituan Nuxt +Vue family bucket, server-side rendering, mailbox verification, passport authentication service, map API reference, mongodb, redis and other technical points
- Do Windows 10 computers need antivirus software installed?
- 单端K总线收发器DP9637兼容L9637
- 基于最小二乘法的线性回归分析方程中系数的估计
- yolov5官方代码解读——前向传播
- 推开机电的大门《电路》(二):功率计算与判断
猜你喜欢
Redis的线程模型
MATLAB绘图命令fimplicit绘制隐函数图形入门详解
Win10系统设置application identity自动提示拒绝访问怎么办
Installation and configuration of Spark and related ecological components - quick recall
Codeforces Round #605 (Div. 3)
STM32LL库——USART中断接收不定长信息
基于最小二乘法的线性回归分析方程中系数的估计
win11一直弹出用户账户控制怎么解决
Win11系统找不到dll文件怎么修复
13.56MHZ刷卡芯片CI521兼容cv520/ci520支持A卡B卡MIFARE协议
随机推荐
General syntax and usage instructions of SQL (picture and text)
Compilation error D8021: Invalid numeric argument '/Wextra' cl command line error d8021 invalid numeric argument '/Wextra'
网络安全抓包
实战美团Nuxt +Vue全家桶,服务端渲染,邮箱验证,passport鉴权服务,地图API引用,mongodb,redis等技术点
LORA芯片ASR6601支持M4内核的远距离传输芯片
编译error D8021 :无效的数值参数“/Wextra” cl command line error d8021 invalid numeric argument ‘/wextra‘
How to add a one-key shutdown option to the right-click menu in Windows 11
Please make sure you have the correct access rights and the repository exists.问题解决
Flink + sklearn - use JPMML implement flink deployment on machine learning model
Lightweight AlphaPose
项目:数据库表的梳理
动态规划理论篇
Win10 computer can't read U disk?Don't recognize U disk how to solve?
Golang 垃圾回收机制详解
7. How to add the Click to RecyclerView and LongClick events
2.登录退出,登录状态检查,验证码
关于c语言的调试技巧
Win10 cannot directly use photo viewer to open the picture
开心一下,9/28名场面合集
MATLAB图形加标注的基本方法入门简介