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=;
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 ;
}
Codeforces Round #266 (Div. 2)B(暴力枚举)的更多相关文章
- Codeforces Round #253 (Div. 2)B(暴力枚举)
就暴力枚举所有起点和终点就行了. 我做这题时想的太多了,最简单的暴力枚举起始点却没想到...应该先想最简单的方法,层层深入. #include<iostream> #include< ...
- Codeforces Round #258 (Div. 2)C(暴力枚举)
就枚举四种情况,哪种能行就是yes了.很简单,关键是写法,我写的又丑又长...看了zhanyl的写法顿时心生敬佩.写的干净利落,简直美如画...这是功力的体现! 以下是zhanyl的写法,转载在此以供 ...
- Codeforces Round #266 (Div.2) B Wonder Room --枚举
题意:给出一个两边长为a,b的矩形,要求增加a和增加b使a*b>=6*n且a*b最小. 解法:设新的a,b为a1,b1,且设a<b,那么a<=a1<=ceil(sqrt(6*n ...
- Codeforces Round #266 (Div. 2)
http://codeforces.com/contest/466 噗,b没写出来啊.a写完后过了40分钟了啊,罚时4次啊!果然太弱 总结: a题看错题,没有考虑m>=n其实也是可行的,导致调了 ...
- Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】
A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #363 (Div. 2) B 暴力
Description You are given a description of a depot. It is a rectangular checkered field of n × m siz ...
- Codeforces Round #266 (Div. 2) D
D. Increase Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #266 (Div. 2)-C,D
C - Number of Ways 直接暴力从前往后寻找.假设找到1/3sum的位置,那么标记++.找到2/3的位置,总数加上标记数. #include<stdio.h> #includ ...
- Codeforces Round #336 (Div. 2)B 暴力 C dp D 区间dp
B. Hamming Distance Sum time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- 磁盘对齐-windows篇
什么是磁盘分区对齐(Disk Alignment.Partition Alignment): Windows的磁盘有一种结构叫做Master Boot Record(MBR), 它的默认大小为63个B ...
- sql两张表关联更新字段
记录,推荐使用第三种,个人觉得比较好 --第一种写法,之前一直用,没有在意 UPDATE sr_t_TCodeUserReciveCfg SET fUserID=a.fUserID,fImportFl ...
- Android签名机制之---签名过程详解
http://www.2cto.com/kf/201512/455388.html 一.前言 又是过了好长时间,没写文章的双手都有点难受了.今天是圣诞节,还是得上班.因为前几天有一个之前的同事,在申请 ...
- Java智能图表类库JChartLib使用介绍
http://www.codeceo.com/article/java-jchartlib.html JChartLib是一款基于Java的智能图表类库,JChartLib不仅有着漂亮的外观,而且支持 ...
- Xamarin简介与Xamarin支持MVC设计模式
Create Native iOS, Android,Mac and Windows apps in C#. 官方网站:http://xamarin.com/ 使用武器 Run a C# app, g ...
- mini2440移植uboot 2014.04(五)
代码上传到github上:https://github.com/qiaoyuguo/u-boot-2014.04-mini2440 前几篇博文: <mini2440移植uboot 2014.04 ...
- PHP 面向对象及Mediawiki 框架分析(二)
mediaHandler可以理解为处理media文件的 /includes/filerepo/file/File.php /** * Get a MediaHandler instance for t ...
- Qt下TCP编程
一.服务器 1.声明一个QTcpServer对象 QTcpServer* serverListener; 2.new出对象 this->serverListener = new QTcpServ ...
- Android系统--灯光系统驱动编写
Android系统开发--Android灯光系统tiny4412_led_class驱动编写 框架分析 led_classdev_4412结构体 创建led_classdev_4412结构体 分配结构 ...
- jack server 常见错误解决方法【转】
本文转载自:https://blog.csdn.net/qq_27061049/article/details/70156200 jack 服务常见错误解决方法 当你编译Android时,你不需要修改 ...