首页 技术 正文
技术 2022年11月18日
0 收藏 599 点赞 2,567 浏览 1677 个字

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

【题意】

让你把长为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());
}
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,075
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,551
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,399
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,811
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,893