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

两个数相乘等于一个数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(暴力枚举)的更多相关文章

  1. Codeforces Round #253 (Div. 2)B(暴力枚举)

    就暴力枚举所有起点和终点就行了. 我做这题时想的太多了,最简单的暴力枚举起始点却没想到...应该先想最简单的方法,层层深入. #include<iostream> #include< ...

  2. Codeforces Round #258 (Div. 2)C(暴力枚举)

    就枚举四种情况,哪种能行就是yes了.很简单,关键是写法,我写的又丑又长...看了zhanyl的写法顿时心生敬佩.写的干净利落,简直美如画...这是功力的体现! 以下是zhanyl的写法,转载在此以供 ...

  3. 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 ...

  4. Codeforces Round #266 (Div. 2)

    http://codeforces.com/contest/466 噗,b没写出来啊.a写完后过了40分钟了啊,罚时4次啊!果然太弱 总结: a题看错题,没有考虑m>=n其实也是可行的,导致调了 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #266 (Div. 2) D

    D. Increase Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #266 (Div. 2)-C,D

    C - Number of Ways 直接暴力从前往后寻找.假设找到1/3sum的位置,那么标记++.找到2/3的位置,总数加上标记数. #include<stdio.h> #includ ...

  9. 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 ...

随机推荐

  1. ThinkPHP框架基础知识一

    ThinkPHP是一个快速.兼容而且简单的轻量级国产PHP开发框架,诞生于2006年初,原名FCS,2007年元旦正式更名为ThinkPHP,遵循Apache2开源协议发布,从Struts结构移植过来 ...

  2. Loadrunder脚本篇——web_submit_data实现提交post请求

    概述 web_link()和web_url()函数都是页面访问型函数,实现HTTP请求中的GET方法,如果需要实现POST方法,可使用web_submit_form或web_submit_data() ...

  3. problem-1003(恢复一下)

    问题: Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequenc ...

  4. FTH: (7156): *** Fault tolerant heap shim applied to current process. This is usually due to previous crashes. ***

    这两天在Qtcreator上编译程序的时候莫名其妙的出现了FTH: (7156): *** Fault tolerant heap shim applied to current process. T ...

  5. (十三)linux文件系统详解(基于ext2文件系统)【转】

    本文转载自:https://blog.csdn.net/FadeFarAway/article/details/53959639 我们知道,一个磁盘可以划分成多个分区,每个分区必须先用格式化工具(例如 ...

  6. Device Tree(一):背景介绍【转】

    本文转载自:http://www.wowotech.net/device_model/why-dt.html 一.前言 作为一个多年耕耘在linux 2.6.23内核的开发者,各个不同项目中各种不同周 ...

  7. 关于图片上传与下载(Java)

    图片的上传 package com.upload; import java.io.IOException;import java.io.PrintWriter; import javax.servle ...

  8. SpringBoot2.0之整合Kafka

    maven依赖: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www. ...

  9. HTML图片热区 map area 标签

    实例 <img src ="planets.gif" alt="Planets" usemap ="#planetmap" /> ...

  10. java基础9(IO流)-File类

    File类 File:文件和目录路径名的抽象表示形式.即java中把文件或者目录都封装成File对象 代码练习1 import java.io.File; public class FileDemo1 ...