A rectangle with the length of A and B must be added to a and B to make a * B> = 6 * n and a * B to the minimum.
Solution: If a and B are set to A1 and B1 and a <B, then a <= A1 <= Ceil (SQRT (6 * n )), then we can enumerate A1 and calculate B1. If B1 <B, then b1 = B and then calculate the area. The minimum value of all the areas is not enough. Then we can enumerate B1 again, the processing is the same as that.
Complexity O (SQRT (n ))
Code:
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#define lll __int64using namespace std;int main(){ lll n,a,b; lll mini,a1,b1; while(scanf("%I64d%I64d%I64d",&n,&a,&b)!=EOF) { mini = (1LL<<62); lll sum = (lll)6*n; for(lll i=a;i<=a+50000LL;i++) { lll tb = sum/i + (sum%i!=0); tb = max(b,tb); lll tarea = i*tb; if(tarea < mini) { mini = tarea; a1 = i; b1 = tb; } } for(lll i=b;i<=b+50000LL;i++) { lll ta = sum/i + (sum%i!=0); ta = max(a,ta); lll tarea = i*ta; if(tarea < mini) { mini = tarea; a1 = ta; b1 = i; } } cout<<mini<<endl<<a1<<" "<<b1<<endl; } return 0;}
View code
Codeforces round #266 (div.2) B wonder room -- Enumeration