题意:给出一个两边长为a,b的矩形,要求增加a和增加b使a*b>=6*n且a*b最小。

解法:设新的a,b为a1,b1,且设a<b,那么a<=a1<=ceil(sqrt(6*n)),那么我们可以枚举a1,然后算出b1,如果b1<b,那么b1 = b,然后算出面积,取所有面积的最小值不就可以了,然后再枚举一次b1,处理与之相同即可。

复杂度O(sqrt(n))

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <algorithm>
  5. #define lll __int64
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. lll n,a,b;
  11. lll mini,a1,b1;
  12. while(scanf("%I64d%I64d%I64d",&n,&a,&b)!=EOF)
  13. {
  14. mini = (1LL<<);
  15. lll sum = (lll)*n;
  16. for(lll i=a;i<=a+50000LL;i++)
  17. {
  18. lll tb = sum/i + (sum%i!=);
  19. tb = max(b,tb);
  20. lll tarea = i*tb;
  21. if(tarea < mini)
  22. {
  23. mini = tarea;
  24. a1 = i;
  25. b1 = tb;
  26. }
  27. }
  28. for(lll i=b;i<=b+50000LL;i++)
  29. {
  30. lll ta = sum/i + (sum%i!=);
  31. ta = max(a,ta);
  32. lll tarea = i*ta;
  33. if(tarea < mini)
  34. {
  35. mini = tarea;
  36. a1 = ta;
  37. b1 = i;
  38. }
  39. }
  40. cout<<mini<<endl<<a1<<" "<<b1<<endl;
  41. }
  42. return ;
  43. }

Codeforces Round #266 (Div.2) B Wonder Room --枚举的更多相关文章

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

    很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实. 两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质. 这道题找 ...

  2. Codeforces Round #266 (Div. 2)

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

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

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

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

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

  5. Codeforces Round #266 (Div. 2) C. Number of Ways

    You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split ...

  6. Codeforces Round #249 (Div. 2) D. Special Grid 枚举

    题目链接: http://codeforces.com/contest/435/problem/D D. Special Grid time limit per test:4 secondsmemor ...

  7. Codeforces Round #422 (Div. 2) B. Crossword solving 枚举

    B. Crossword solving     Erelong Leha was bored by calculating of the greatest common divisor of two ...

  8. Codeforces Round #666 (Div. 2) B. Power Sequence (枚举)

    题意:有一个长度为\(n\)的序列,你每次可以对序列重新排序,然后花费\(1\)使某个元素加减\(1\),多次操作后使得新序列满足\(a_{i}=c^i\),\(c\)是某个正整数,求最小花费. 题解 ...

  9. Codeforces Round #669 (Div. 2) B. Big Vova (枚举)

    题意:有一个长度为\(n\)的序列,你需要对其重新排序,构造一个新数组\(c\),\(c_{i}=gcd(a_{1},...,a{i})\)并且使得\(c\)的字典序最小. 题解:直接跑\(n\)次, ...

随机推荐

  1. 【Asphyre引擎】学习笔记(二)

    转一篇火人论坛那边的一份学习文档,我简单排一下版,希望对入门者有帮助. 感谢China Yang,这份文档也帮助我快速入了门. 和我一起学 Asphyre Sphinx Framework v1.0. ...

  2. 静态导入Static import

    静态导入Static import 要使用静态成员(方法和变量)我们必须给出提供这个静态成员的类. 使用静态导入可以使被导入类的静态变量和静态方法在当前类直接可见,使用这些静态成员无需再给出他们的类名 ...

  3. 详解;(function ($,window,document,undefined){...})(jQuery,window,document);

    1.代码最前面的分号,可以防止多个文件压缩合并以为其他文件最后一行语句没加分号,而引起合并后语法错误. 2.匿名函数(function(){})();:由于Javascript执行表达式是从圆括号里面 ...

  4. File类的常用方法

    public static void GetFileInfo()    {                File file=new File("e:","two.txt ...

  5. Lucene总体架构

    Lucene总的来说是:• 一个高效的,可扩展的,全文检索库.• 全部用Java实现,无须配置.• 仅支持纯文本文件的索引(Indexing)和搜索(Search).• 不负责由其他格式的文件抽取纯文 ...

  6. 简单认识UISwitch

    以下是常用属性: self.mySwitch.layer.cornerRadius = 15;   // 边框圆角角度 self.mySwitch.layer.borderWidth = 2;  // ...

  7. 多线程基础(二)pthread的了解

    IOS中多线程的实现方案   了解NSOperation(代码) 所有的方法都是pthread开头的   然后再搞一条线程 pthread_create方法有返回值,作用:判断线程创建是否成功?   ...

  8. 设置IE兼容模式的几种方法

    一.指定文件兼容性模式要为你的网页指定文件模式,需要在你的网页中使用meta元素放入x-ua-compatible http-equiv 标头.1. 强制ie8使用ie8模式来解析,而且那个兼容性视图 ...

  9. 【mysql】关于临时表

    mysql官方的介绍 In some cases, the server creates internal temporary tables while processing queries. Suc ...

  10. Spring4定时器 cronTrigger和simpleTrigger实现方法

    spring4定时器 cronTrigger和simpleTrigger实现方法 Quartz 是个开源的作业调度框架,为在 Java 应用程序中进行作业调度提供了简单却强大的机制.Quartz 允许 ...