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

两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质。

这道题找出a和b中最小的那个,然后开始枚举,一直枚举到sqrt(6*n)的向上取整。这样所有可能是答案的情况都有啦。再干别的都是重复的或者肯定不是最小面积的。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<map>
  7. #include<set>
  8. #include<vector>
  9. #include<algorithm>
  10. #include<stack>
  11. #include<queue>
  12. #include<cctype>
  13. #include<sstream>
  14. using namespace std;
  15. #define INF 1000000000
  16. #define eps 1e-8
  17. #define pii pair<int,int>
  18. #define LL long long int
  19. LL a,b,n,s,a1,b1,t;
  20. int main()
  21. {
  22. //freopen("in8.txt","r",stdin);
  23. //freopen("out.txt","w",stdout);
  24. scanf("%I64d%I64d%I64d",&n,&a,&b);
  25. s=;
  26. t=ceil(sqrt(*n));
  27. LL sum=*n;
  28. if(n*<=a*b)
  29. cout<<a*b<<endl<<a<<' '<<b<<endl;
  30. else
  31. {
  32. bool c=;
  33. if(a>b)
  34. {
  35. c=;
  36. swap(a,b);
  37. }
  38. for(LL i=a;i<=t;i++)
  39. {
  40. LL t=max(b,sum/i+(sum%i!=));
  41. if(i*t<s)
  42. {
  43. a1=i,b1=t,s=i*t;
  44. }
  45. }
  46. if(c)
  47. cout<<s<<endl<<b1<<' '<<a1<<endl;
  48. else
  49. cout<<s<<endl<<a1<<' '<<b1<<endl;
  50. }
  51. //fclose(stdin);
  52. //fclose(stdout);
  53. return ;
  54. }

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.  Link 

    GNU/Linux, Bash, C, PHP, Perl, JavaScript, Vim, Git http://blog.sanctum.geek.nz/about   中文數學詞典 http: ...

  2. JS字符串数组转换

    字符串转数组: str.split(';') 数组转字符串: arr.join(';')

  3. Linux基本命令 vim命令(一)

    vim的三种工作模式 命令模式.输入模式和编辑模式的相互转换,如图 命令模式:使用 Vim 编辑文件时,默认处于命令模式.在此模式下,可以使用上.下.左.右键或者 k.j.h.l 命令进行光标移动,还 ...

  4. CSS伪元素实现的3D按钮

    在线演示 本地下载

  5. python:字典的方法

    1.查找字典中的key对应的值和key是否存在(get,has_key)dict.get(key, default = None) :返回字典中key对应的值,若key不存在字典中,则返回defaul ...

  6. Centos6.5下ElasticSearch1.4.4的安装

    1.下载ElasticSearch 官网地址 https://www.elastic.co/ 2.安装elasticsearch-1.4.4.tar.gz tar -zxvf elasticsearc ...

  7. [转载]Google Android开发精华教程

    原文地址:Android开发精华教程">Google Android开发精华教程作者:huiyi8zai Android是Google于2007年11月5日宣布的基于Linux平台的开 ...

  8. wareshark网络协议分析之DHCP

    声明:本文关于DHCP协议介绍部分摘自百度百科 一.DHCP协议介绍: DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)是一个局域网的网络协议,使用 ...

  9. QT5中如何使用QFtp类

    QT5中如何使用QFtp类 http://2662597.blog.51cto.com/2652597/1279806 由于QT5对QML的支持有很大的改进,所以打算将原来基于QT4的程序移植到QT5 ...

  10. svg_鼠标手型

    1. 貌似是 属性 "cursor :pointer;",待测试. 2.