Codeforces round #266 (Div. 2) B (brute force enumeration)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.