题目链接:http://codeforces.com/problemset/problem/466/B
题意:有一个a*b大小的房间,有n的学生,每一个学生需要6单位的面积,也就是要一个6*n大小的房间,可以将任意增大a和b,问如何使a*b大于6*n且差值最小
思路:因为知道最后面积一定是大于6*n,所以只要分别枚举a和b的大小就可以求出另一个参数的大小,如果求出另一个参数不是整形就让它取整加1就好(这个地方出了几次问题)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define inf 0x3f3f3f3f3f3f3f3f3f3f3f
#define LL long long
using namespace std;
int main()
{
LL n,a,b;
while (scanf("%I64d%I64d%I64d",&n,&a,&b)!=EOF)
{
LL tem=6*n,minx=inf,resa,resb;
tem=sqrt(tem);
for (LL i=a;i<=tem;i++)
{
LL ta=i,tb=(n*6)/ta;
if (tb*ta!=n*6) tb++;
tb=max(tb,b);
if (ta*tb<minx)
{
minx=ta*tb;
resa=ta;
resb=tb;
}
}
for (LL i=b;i<=tem;i++)
{
LL tb=i,ta=(n*6)/tb;
if (tb*ta!=n*6) ta++;
ta=max(ta,a);
if (ta*tb<minx)
{
minx=ta*tb;
resa=ta;
resb=tb;
}
}
if (a*b>=n*6) printf("%I64d\n%I64d %I64d\n",a*b,a,b);
else printf("%I64d\n%I64d %I64d\n",minx,resa,resb);
}
}