【CODEFORCES】 B. Wonder Room

B. Wonder Room
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The start of the new academic year brought about the problem of accommodation students into dormitories. One of such dormitories has a a × b square meter wonder room. The caretaker wants to accommodate exactly n students there. But the law says that there must be at least 6 square meters per student in a room (that is, the room for n students must have the area of at least 6n square meters). The caretaker can enlarge any (possibly both) side of the room by an arbitrary positive integer of meters. Help him change the room so as all n students could live in it and the total area of the room was as small as possible.

Input

The first line contains three space-separated integers na and b (1 ≤ n, a, b ≤ 109) — the number of students and the sizes of the room.

Output

Print three integers sa1 and b1 (a ≤ a1b ≤ b1) — the final area of the room and its sizes. If there are multiple optimal solutions, print any of them.

Sample test(s)
input
3 3 5
output
18
3 6
input
2 4 4
output
16
4 4



题解:我果然还是太水了....这题一开始竟然没写出来....

对于a1,从a一直枚举到sqrt(6*n),算出每一个b1,与现有的答案比较,如果更优就输出。对于b1同理,最后输出答案和a1,b1即可。

#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

long long  n,a,b,t,p,ans,a1,b1;
int main()
{
    scanf("%I64d%I64d%I64d",&n,&a,&b);
    if (n*6<=a*b)
    {
        cout <<a*b<<endl;
        cout <<a<<" "<<b;
    }
    else
    {
        t=a; p=b;
        for (t=a;t<=ceil(sqrt(6*n));t++)
        {
            p=ceil((6*n)*1.0/t);
            if (p<b) p=b;
            if (t*p<ans || ans==0)
            {
                a1=t; b1=p;
                ans=a1*b1;
            }
            if (ans==6*n)
            {
                cout <<ans<<endl;
                cout <<a1<<" "<<b1;
                return 0;
            }
        }
        for (p=b;p<=ceil(sqrt(6*n));p++)
        {
            t=ceil((6*n)*1.0/p);
            if (t<a) t=a;
            if (t*p<ans || ans==0)
            {
                a1=t; b1=p;
                ans=a1*b1;
            }
            if (ans==6*n)
            {
                cout <<ans<<endl;
                cout <<a1<<" "<<b1;
                return 0;
            }
        }
        cout <<ans<<endl;
        cout <<a1<<" "<<b1;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值