【Codeforces 466B】Wonder Room
【链接】 我是链接,点我呀:)
【题意】
让你把长为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());
}
}
}
【Codeforces 466B】Wonder Room的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- 基于ELK的传感器数据分析练习
目录 Sensor Data Analytics Application 数据构成 数据模型设计 Logstash配置 Kibana可视化 Sensor Data Analytics Applicat ...
- asp.net mvc6学习资料整理
十分钟轻松让你认识ASP.NET MVC6 http://www.cnblogs.com/n-pei/p/4272105.html ASP.NET 5系列教程 (六): 在 MVC6 中创建 Web ...
- bzoj 1673: [Usaco2005 Dec]Scales 天平【dfs】
真是神奇 根据斐波那契数列,这个a[i]<=c的最大的i<=45,所以直接搜索即可 #include<iostream> #include<cstdio> usin ...
- P3990 [SHOI2013]超级跳马
传送门 首先不难设\(f[i][j]\)表示跳到\((i,j)\)的方案数,那么不难得到如下转移 \[f[i][j]=\sum\limits_{k=1}^{\frac n2}f[i-2k+1][j-1 ...
- CSS布局大全
前几天面试,问我某布局感觉回答不是很OK所以研究了一下各种布局. 一.单列布局 1.普通布局(头部.内容.底部) <div class="container"> < ...
- n阶完全生成图的数量
有些事不是看到了希望才去坚持,而是坚持了才会看到希望 问题 I: 星际之门(一) 时间限制: Sec 内存限制: MB 提交: 解决: [提交][状态][讨论版] 题目描述 公元3000年,子虚帝国统 ...
- 打开VMware Workstation,虚拟机不见了
1 打开VM,发现虚拟机不见了 如图所示: 此时先别急着再次安装虚拟机. 2 先打开设备上所有已安装过的虚拟机,看你需要的还在不在 3 总结 如果打开后发现你要的虚拟机还存在,直接打开就好.否则,就得 ...
- ElasticSearch学习笔记--安装
1.安装ElasticSearch https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html 这 ...
- jsp学习笔记 - 内置对象 application
---恢复内容开始--- 1.application一般用this.getServletContext()替代 2.appllication有一个非常有用的函数 getRealPath(),获取绝对路 ...
- 字符编码方式ASCII、Unicode、UTF-8
一.ASCII 1.介绍 即American Standard Code for Information Interchange(美国信息交换标准代码),是基于拉丁字母的,主要用于显示现代英语和其他西 ...