当前位置:网站首页>Codeforces Round #624 (Div. 3)
Codeforces Round #624 (Div. 3)
2022-08-02 14:10:00 【老顽固也可爱】
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 ,找出操作次数最少的。
这个题目用普通的正面思考会很复杂,第一个想到的就是bfs,但是用bfs很容易爆内存。
简单的方法是换一种思路:从满足b%a== 0&&c%b == 0条件开始找最小的值。
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;
}
边栏推荐
- Daily - Notes
- Open the door of power and electricity "Circuit" (2): Power Calculation and Judgment
- 【系统设计与实现】基于flink的分心驾驶预测与数据分析系统
- 专硕与学硕
- pygame绘制弧线
- Win10无法连接打印机怎么办?不能使用打印机的解决方法
- cmake配置libtorch报错Failed to compute shorthash for libnvrtc.so
- FP7195降压恒流PWM转模拟调光零压差大功率驱动方案原理图
- Mapreduce环境详细搭建和案例实现
- arm push/pop/b/bl汇编指令
猜你喜欢
What should I do if the Win10 system sets the application identity to automatically prompt for access denied?
How to reinstall Win7 system with U disk?How to reinstall win7 using u disk?
总结计算机网络超全面试题
Win10电脑需要安装杀毒软件吗?
MATLAB绘图函数ezplot入门详解
Win11怎么在右键菜单添加一键关机选项
Win10 computer can't read U disk?Don't recognize U disk how to solve?
[STM32 Learning 1] Basic knowledge and concepts are clear
Win11系统找不到dll文件怎么修复
刷卡芯片CI520可直接PIN对PIN替换CV520支持SPI通讯接口
随机推荐
Use tencent cloud builds a personal blog
C语言函数参数传递模式入门详解
LeetCode2 电话号码的字母组合
Summarize computer network super comprehensive test questions
Mysql的锁
用U盘怎么重装Win7系统?如何使用u盘重装系统win7?
Redis的线程模型
Binder机制(下篇)
CS4398音频解码替代芯片DP4398完全兼容DAC解码
arm push/pop/b/bl汇编指令
MATLAB绘制平面填充图入门详解
FP7128内置MOS降压恒流调光深度0.01%高辉共阳调光方案
define #使用
将SSE指令转换为ARM NEON指令
利用plot_surface命令绘制复杂曲面入门详解
pygame图像连续旋转
关于c语言的调试技巧
网络安全抓包
CMAKE
深入理解Golang之Map