Codeforces Round #266 (Div. 2)B(暴力枚举)
2024-09-28 13:27:32
很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实。
两个数相乘等于一个数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 ;
}
最新文章
- FAT32 FAT区__FAT表解析
- 0027 Java学习笔记-面向对象-(非静态、静态、局部、匿名)内部类
- three.js入门2
- Linux 搭建svn服务器
- (一)s3c2440 地址分配讲解 (很难很纠结)
- JS - To my gril
- 利用Microsoft Azure Machine Learning Studio创建机器学习实例
- FZOJ2110 star(DFS)
- 【小结】有关mysql扩展库和mysqli扩展库的crud操作封装
- Android程序捕获未处理异常,处理与第三方方法冲突时的异常传递
- Java中double变量精确到小数点后几(2)位
- Linux 分区挂载方案
- VMware Workstation 12 Pro 之安装Windows10 EP系统
- flask 分页
- JAVA面向对象-----值交换(基本数据类型 数组类型 对象的值 字符串的)
- AGC 030D.Inversion Sum(DP 期望)
- APK优化工具zipalign的详细介绍和使用
- Mybatis十( mybatis其他使用)
- BZOJ3772精神污染
- 20161226xlVBA演示文稿替换文字另存pdf