Simple brute-force enumeration, but it took me so long, it can be seen that my basic skills are not solid enough.
If the multiplication of two numbers equals to a number of 6 * n, I can enumerate one of them, and enumerate to SQRT (6 * n, this is a very common nature of brute force solutions.
Find the smallest one in A and B, and start enumeration until the ascending order of SQRT (6 * n. In this way, there may be answers. The other items are repeated or certainly not the smallest area.
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<map>#include<set>#include<vector>#include<algorithm>#include<stack>#include<queue>#include<cctype>#include<sstream>using namespace std;#define INF 1000000000#define eps 1e-8#define pii pair<int,int>#define LL long long intLL a,b,n,s,a1,b1,t;int main(){ //freopen("in8.txt","r",stdin); //freopen("out.txt","w",stdout); scanf("%I64d%I64d%I64d",&n,&a,&b); s=10123456789; t=ceil(sqrt(6*n)); LL sum=6*n; if(n*6<=a*b) cout<<a*b<<endl<<a<<‘ ‘<<b<<endl; else { bool c=0; if(a>b) { c=1; swap(a,b); } for(LL i=a;i<=t;i++) { LL t=max(b,sum/i+(sum%i!=0)); if(i*t<s) { a1=i,b1=t,s=i*t; } } if(c) cout<<s<<endl<<b1<<‘ ‘<<a1<<endl; else cout<<s<<endl<<a1<<‘ ‘<<b1<<endl; } //fclose(stdin); //fclose(stdout); return 0;}
Codeforces round #266 (Div. 2) B (brute force enumeration)