[CF1311D] Three Integers - 数学

Solution
枚举 \(a\),枚举 \(b\ s.t. a|b\),则 \(c\) 一定是 \([c/b]b\) 或 \(([c/b]+1)b\)
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 20000;
int a,b,c,T,A,B,C,ans=1e9;
void upd(int i,int j,int k) {
int tmp=abs(i-A)+abs(j-B)+abs(k-C);
if(tmp<ans) {
ans=tmp;
a=i; b=j; c=k;
}
}
signed main() {
ios::sync_with_stdio(false);
cin>>T;
while(T--) {
cin>>A>>B>>C;
ans=1e9;
for(int i=1;i<=N;i++) {
for(int j=i;j<=N;j+=i) {
int k;
k=(C/j)*j;
upd(i,j,k);
k+=j;
upd(i,j,k);
}
}
cout<<ans<<endl;
cout<<a<<" "<<b<<" "<<c<<endl;
}
}
[CF1311D] Three Integers - 数学的更多相关文章
- interesting Integers(数学暴力||数论扩展欧几里得)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAwwAAAHwCAIAAACE0n9nAAAgAElEQVR4nOydfUBT1f/Hbw9202m0r8
- [LeetCode] 数学计算模拟类问题:加法,除法和幂,注意越界问题。题 剑指Offer,Pow(x, n) ,Divide Two Integers
引言 数学计算的模拟类题目,往往是要求实现某种计算(比如两数相除),实现的过程中会有所限定,比如不允许乘法等等. 这类题目首先要注意计算过程中本身的特殊情况.比如求相除,则必须首先反映过来除数不能为0 ...
- Divisors of Two Integers CodeForces - 1108B (数学+思维)
Recently you have received two positive integer numbers xx and yy. You forgot them, but you remember ...
- Sum of Consecutive Integers LightOJ - 1278(推公式 数学思维)
原文地址:https://blog.csdn.net/qq_37632935/article/details/79465213 给你一个数n(n<=10^14),然后问n能用几个连续的数表示; ...
- [LeetCode] Sum of Two Integers 两数之和
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...
- ACM: FZU 2110 Star - 数学几何 - 水题
FZU 2110 Star Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Pr ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 62. Divide Two Integers
Divide Two Integers Divide two integers without using multiplication, division and mod operator. 思路: ...
- UVA 113 Power of Cryptography (数学)
Power of Cryptography Background Current work in cryptography involves (among other things) large p ...
随机推荐
- 场景6:具有OpenvSwitch的提供商网络
此场景描述了使用带有Open vSwitch(OVS)的ML2插件的OpenStack网络服务的提供者网络实现. 在OpenStack网络引入分布式虚拟路由器之前,所有网络通信都通过一个或多个专门的网 ...
- python day01练习和作业
习题:1.简述编译型与解释型语言的区别,且分别列出你知道的哪些语言属于编译型,哪些属于解释型编译型语言:优点:执行速度快 缺点:维护成本高,跨平台性差解释型语言:优点:维护成本低,跨平台性好 缺点:执 ...
- Dubbox 环境搭建-新(Windows下)
分布式服务框架 dubbo/dubbox 入门示例 dubbo是一个分布式的服务架构,可直接用于生产环境作为SOA服务框架. 官网首页:http://dubbo.io/ ,官方用户指南 http:// ...
- 变量引用的错误:UnboundLocalError: local variable 'range' referenced before assignment
class Battery(): """一次模拟电瓶汽车的简单尝试""" def __init__(self,battery_size = ...
- 20194651—自动生成四则运算题第一版报告chris
1.需求分析: (1)自动生成四则运算算式(+ - * /),或两则运算(+ -). (2)剔除重复算式. (3)题目数量可定制. (4)相关参数可控制. (5)生成的运算题存储到外部文件中. 2 ...
- Codeforces 924 A Tritonic Iridescence(暴力集合交集、相等)
题目链接:点击打开链接 There is a rectangular grid of n rows of m initially-white cells each. Arkady performed ...
- Linux系统资料
Linux的心得: 1)Linux由众多微内核组成,其源代码完全开源: 2)Linux继承了Unix的特性,具有非常强大的网络功能,其支持所有的因特网协议,包括TCP/IPv4. TCP/IPv6和链 ...
- phpstorm+xmapp post不能传值
https://blog.csdn.net/apple_wheat/article/details/72937035 问题的原因在于: PhpStorm默认使用的是自带的内部服务器,却不使用XAMPP ...
- 云服务器InfluxDB & Chronograf配置
环境: 阿里云服务器 Ubuntu 18.04.3 LTS InfluxDB 1.7.10 (截至2020.2.20最新版) chonograf 1.8.0 (2020.2.19推出) 配置建议: 不 ...
- JMeter+Grafana+Influxdb搭建可视化性能测试监控平台(待继续完善。。。)
influxdb下载.安装.配置.启动 InfluxDB是一个当下比较流行的时序数据库,InfluxDB使用 Go 语言编写,无需外部依赖,安装配置非常方便,适合构建大型分布式系统的监控系统. 下载: ...