zoukankan      html  css  js  c++  java
  • 【Codeforces 466B】Wonder Room

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

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

    【题解】

    假设a< b 然后我们枚举新的a(较小的哪一个)为newa newa只需要枚举到ceil(sqrt(6*n))就好 因为如果newa>ceil(sqrt(6*n))的话 得到的newb = ceil(sqrt(6*n))/newa newb肯定是小于等于ceil(sqrt(6*n))的 而我们之前newa已经枚举过这种情况了,所以不可能得到更优解。 newb判断一下是不是大于等于b就好 (注意我们在枚举newa的时候,得到的newb ,也会满足newa<=newb) (判断的时候肯定是小的和小的比,大的和大的比,所以一开始的时候,显然小的值放在a,大的值放在b,然后枚举小的值一直增大)

    【代码】

    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());
            }
        }
    }
    
  • 相关阅读:
    bootstrap基础(四)
    bootstrap基础(三)
    bootstrap基础(二)
    python @staticmethod和@classmethod
    python的数据类型可变不可变
    json.dumps()和json.loads()和eval()
    Linux如何查看端口状态
    python 同时遍历两个list
    dogedoge浏览器爬取标题
    虚拟机数据库连接Windows本地数据库
  • 原文地址:https://www.cnblogs.com/AWCXV/p/10505402.html
Copyright © 2011-2022 走看看