【链接】 我是链接,点我呀:)

【题意】

让你把长为a,宽为b的房间扩大(长和宽都能扩大)。
使得它的面积达到6*n
问你最小的能满足要求的面积是多少
输出对应的a和b

【题解】

假设aceil(sqrt(6*n))的话
得到的newb = ceil(sqrt(6*n))/newa
newb肯定是小于等于ceil(sqrt(6*n))的
而我们之前newa已经枚举过这种情况了,所以不可能得到更优解。
newb判断一下是不是大于等于b就好
(注意我们在枚举newa的时候,得到的newb ,也会满足newa

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = 50000;
static class Task{ long n,a,b;
public void solve(InputReader in,PrintWriter out) {
n = in.nextLong();a = in.nextLong();b = in.nextLong();
if (a*b>=6*n) {
out.println(a*b);
out.println(a+" "+b);
return;
}
long temp = (long)Math.sqrt(6*n);
if (temp*temp<6*n) temp++;
long ans = (long)(1e18)+100;
long temp1 = 0,temp2 =0;
boolean f = false;
if (a>b) {
long temp3 = a;a = b;b = temp3;
f =true;
} for (long newa = a;newa <=temp;newa++) {
long newb = (6*n)/newa;
if (newa*newb<(6*n)) newb++; if (newb < b) continue;
if (newa*newb>=6*n && newa*newb<ans) {
ans = Math.min(ans, newa*newb);
temp1 = newa;temp2 = newb;
}
}
if (f) {
long temp3 = temp1;temp1 = temp2;temp2 = temp3;
}
out.println(ans);
out.println(temp1+" "+temp2);
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
} public long nextLong() {
return Long.parseLong(next());
}
}
}

最新文章

  1. 两个img之间出现间隙的解决方法
  2. Nginx HA 及https配置部署
  3. Oracle数据库的引导过程
  4. Oracle自动执行任务(存储过程)
  5. 翻扣告诉你外出旅游时实用的一些小tips
  6. 谈谈个人网站的建立(二)—— lucene的使用
  7. 两种实现方式mycat多租户,枚举分片,注解拦截
  8. Intel_CS_WebRTC 验证性测试
  9. CentOS 7 Nginx1.12.2平滑升级到新版本nginx-1.13.3
  10. JavaScript 之 预编译 作用域,作用域链
  11. gitlab部署步骤+汉化
  12. 2019,UI设计师必备神器
  13. 【并查集的另一个思考方向】POJ1456
  14. mysql关联更新update
  15. div居中布局
  16. Python小白学习之路(二十一)—【迭代器】
  17. Loadrunner参数化逗号报错解决方法
  18. 单元测试+内存、SD卡、SP读写+XmlPullParser
  19. disable Nouveau kernel driver
  20. 51nod-1636-dp

热门文章

  1. KVPhone,VOS官方的SIP软电话电脑客户端
  2. bzoj 1657: [Usaco2006 Mar]Mooo 奶牛的歌声【单调栈】
  3. H - Where is the Marble?(set+vector)
  4. vue中引入swiper插件
  5. 转 linux之sed命令详解
  6. 关于dbms_output包的使用
  7. EasyUI系列学习(六)-Tooltip(提示框)
  8. Modbus通讯错误检测方法
  9. php数据类型的转换
  10. 解决opencv在pycharm中无代码自动提示的bug