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;
    }
  • 相关阅读:
    存储引擎的优缺点及增删改查基本操作
    安装Mariadb
    Mysql 入门概念
    Nginx语法着色
    find用法,文件压缩和lsof和cpio
    软件包管理
    Django 生成六位随机图片验证码
    Django自定义过滤器和自定义标签
    Django零碎知识点
    jQuery实现淡入淡出样式轮播
  • 原文地址:https://www.cnblogs.com/zywscq/p/3989422.html
Copyright © 2011-2022 走看看