zoukankan      html  css  js  c++  java
  • Codeforces Round #266 (Div. 2)B(暴力枚举)

    很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实。

    两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质。

    这道题找出a和b中最小的那个,然后开始枚举,一直枚举到sqrt(6*n)的向上取整。这样所有可能是答案的情况都有啦。再干别的都是重复的或者肯定不是最小面积的。

    #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 int
    LL 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;
    }
  • 相关阅读:
    洛谷 P2327 [SCOI2005]扫雷 题解
    P1388 算式 题解
    P1281 书的复制 题解
    P2896 [USACO08FEB]一起吃饭Eating Together 题解
    P1140 相似基因 题解
    变量的解构赋值
    let 和 const 命令
    第一阶段站立会议8
    第一阶段站立会议7
    第一阶段站立会议6
  • 原文地址:https://www.cnblogs.com/zywscq/p/3989422.html
Copyright © 2011-2022 走看看