Codeforces round #266 (div.2) B wonder room -- Enumeration

Source: Internet
Author: User

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

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.