codeforce 1311 D. Three Integers
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
inputCopy
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
outputCopy
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
纯暴力枚举(有点技巧,小剪枝)
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e15 + 5;
int main()
{
int t;
cin >> t;
while (t--)
{
long long a, b, c, a1, b1, c1;
scanf("%lld %lld %lld", &a, &b, &c);
long long cnt = maxn;
for (long long k = 1; k <=5*c; k++)
{
for (long long i = 1; i*k<=5*c; i++)
for (long long j = 1;i*k* j <=5*c ; j++)
{
long long temp = abs(k - a) + abs(i * k - b) + abs(j * i * k - c);
if (temp < cnt)
{
cnt = temp;
a1 = k;
b1 = i * k;
c1 = i * j * k;
}
// else
// break;
}
}
printf("%lld\n", cnt);
printf("%lld %lld %lld\n", a1, b1, c1);
}
}
codeforce 1311 D. Three Integers的更多相关文章
- codeforce 1311 C. Perform the Combo 前缀和
You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...
- F. Moving Points 解析(思維、離散化、BIT、前綴和)
Codeforce 1311 F. Moving Points 解析(思維.離散化.BIT.前綴和) 今天我們來看看CF1311F 題目連結 題目 略,請直接看原題. 前言 最近寫1900的題目更容易 ...
- 解题报告:codeforce 7C Line
codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...
- Two progressions CodeForce 125D 思维题
An arithmetic progression is such a non-empty sequence of numbers where the difference between any t ...
- CodeForce 577B Modulo Sum
You are given a sequence of numbers a1, a2, ..., an, and a number m. Check if it is possible to choo ...
- CodeForce 192D Demonstration
In the capital city of Berland, Bertown, demonstrations are against the recent election of the King ...
- CodeForce 176C Playing with Superglue
Two players play a game. The game is played on a rectangular board with n × m squares. At the beginn ...
- CodeForce 222C Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractio ...
- CodeForce 359C Prime Number
Prime Number CodeForces - 359C Simon has a prime number x and an array of non-negative integers a1, ...
随机推荐
- javascript入门 之 ztree(二 标准json数据)
1.代码 <!DOCTYPE html> <HTML> <HEAD> <TITLE> ZTREE DEMO - Standard Data </T ...
- redis修改密码以及验证登录,启动服务常用命令
1.通过配置文件,直接修改 2.启动然后使用密码验证登录 3.redis常用命令 启动服务:redis-server --service-start重启服务:service redis restart ...
- 一口气说出 4种 LBS “附近的人” 实现方式,面试官笑了
引言 昨天一位公众号粉丝和我讨论了一道面试题,个人觉得比较有意义,这里整理了一下分享给大家,愿小伙伴们面试路上少踩坑.面试题目比较简单:"让你实现一个附近的人功能,你有什么方案?" ...
- matplotlib BlendedGenericTransform(混合变换)和CompositeGenericTransform(复合变换)
2020-04-10 23:31:13 -- Edit by yangrayBlendedGenericTransform是Transform的子类,支持在x / y方向上使用不同的变换.(博主翻译为 ...
- SpringMVC框架详细教程(六)_HelloWorld
HelloWorld 在src下创建包com.pudding.controller,然后创建一个类HelloWorldController: package com.pudding.controlle ...
- 智能指针 unique_ptr
unique_ptr 不共享它的指针.它无法复制到其他 unique_ptr,无法通过值传递到函数,也无法用于需要副本的任何标准模板库 (STL) 算法. 1.不能进行复制构造和赋值操作(unique ...
- excel完成数据库数据的批量插入
业务场景: 开发过程中往往会遇到这样情况就是产品直接给我们一堆数据,让咱们直接导入到后台数据库中,这时候咱们只需要在excel表中进行直接操作即可,如图所示(以河北省的编号为例): 而对应的数据表为: ...
- Scanner的小细节
Scanner对象是用来接收键盘输入的数据的,可以接收字符串,数字,浮点数,大数等多种数据. Scanner scanner = new Scanner(System.in); System.out. ...
- 014-预处理指令-C语言笔记
014-预处理指令-C语言笔记 学习目标 1.[掌握]枚举 2.[掌握]typedef关键字 3.[理解]预处理指令 4.[掌握]#define宏定义 5.[掌握]条件编译 6.[掌握]static与 ...
- AJ学IOS(39)UI之核心动画之CABasicAnimation(基础动画)
AJ分享,必须精品 一.CABasicAnimation简介 CAPropertyAnimation的子类 属性解析: fromValue:keyPath相应属性的初始值 toValue:keyPat ...