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

两个数相乘等于一个数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=;
t=ceil(sqrt(*n));
LL sum=*n;
if(n*<=a*b)
cout<<a*b<<endl<<a<<' '<<b<<endl;
else
{
bool c=;
if(a>b)
{
c=;
swap(a,b);
}
for(LL i=a;i<=t;i++)
{
LL t=max(b,sum/i+(sum%i!=));
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 ;
}

最新文章

  1. FAT32 FAT区__FAT表解析
  2. 0027 Java学习笔记-面向对象-(非静态、静态、局部、匿名)内部类
  3. three.js入门2
  4. Linux 搭建svn服务器
  5. (一)s3c2440 地址分配讲解 (很难很纠结)
  6. JS - To my gril
  7. 利用Microsoft Azure Machine Learning Studio创建机器学习实例
  8. FZOJ2110 star(DFS)
  9. 【小结】有关mysql扩展库和mysqli扩展库的crud操作封装
  10. Android程序捕获未处理异常,处理与第三方方法冲突时的异常传递
  11. Java中double变量精确到小数点后几(2)位
  12. Linux 分区挂载方案
  13. VMware Workstation 12 Pro 之安装Windows10 EP系统
  14. flask 分页
  15. JAVA面向对象-----值交换(基本数据类型 数组类型 对象的值 字符串的)
  16. AGC 030D.Inversion Sum(DP 期望)
  17. APK优化工具zipalign的详细介绍和使用
  18. Mybatis十( mybatis其他使用)
  19. BZOJ3772精神污染
  20. 20161226xlVBA演示文稿替换文字另存pdf

热门文章

  1. Numpy用于数组的文件输入输出
  2. 方阵行列式并行化计算(OpenMP,MPI),并计算加速比
  3. 基于 GitHub 搭建/创建自己博客 DIY
  4. 大数据架构之:Spark
  5. 【Tech】单点登录系统CAS服务器端搭建及实现用户名密码由MYSQL数据库验证
  6. 【Head First Servlets and JSP】笔记9:属性的作用域、线程安全
  7. [SCOI2013]火柴棍数字(背包)
  8. 释放Linux系统缓存
  9. Pytorch的gather用法理解
  10. Whitewidow:SQL 漏洞自动扫描工具