codeforce F. Multicolored Markers
2024-10-21 11:41:03
http://codeforces.com/contest/1029/problem/F
这道题真的一点都不难……………………………………………………
对于大矩形面积a+b,从差距最小的因数开始遍历,直到遇到第一个a、b中的任何一个,能变成一个矩形并能放在大矩形中(因为最后的大矩形的面积一定等于a+b,所以剩余空间一定可以填补),我们就找到了解。
1 import java.util.*;
2
3 public class A {
4 public static void main(String[] args) {
5 Scanner io = new Scanner(System.in);
6 long a = io.nextLong(), b = io.nextLong(), c = a + b;
7 long min = 0, max = 0;
8
9 for (long i = (long) Math.sqrt(c); i >= 1; i--) {
10 if (c % i == 0) {
11 min = i;
12 max = c / i;
13
14 //当两个因数差距越来越大时,max的长度比min大一倍多,所以max妥妥超时
15 for (long j = min; j >= 1; j--) {
16 if (a % j == 0 && a / j <= max || b % j == 0 && b / j <= max) {
17 System.out.println((min + max) * 2);
18 return;
19 }
20 }
21 }
22 }
23
24 }
25 }
最新文章
- sessionid如何产生?由谁产生?保存在哪里?
- webapi 通过dynamic 接收可变参数
- 从WinCE到Linux
- iOS -- 神战
- 69道Spring面试题和答案
- Orchard官方文档翻译(十一) 使用Tags组织文本
- 程序员定制的中州韵(rime)windows版(小狼毫)微软双拼输入法
- Visual Studio 自定义控件不显示在工具箱
- 工具栏ToolStrip能触发焦点控件的Leave、Validating、DataError等事件以验证数据 z
- Linux-ubuntu
- ANT的安装和配置(windows)
- Windows 下 pip和easy_install 的安装与使用
- js scroll 教程
- jQuery语音播放插件
- qdoc 简介
- 关于LeetCode的Largest Rectangle in Histogram的低级解法
- numpy.squeeze()是干啥的
- 妙谈js回调函数的理解!
- luogu 2014 选课 树上背包
- 生产环境elasticsearch5.0报错IllegalArgumentException: number of documents in the index cannot exceed 2147483519的处理