题意:给出一个两边长为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))

代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define lll __int64
using namespace std; int main()
{
lll n,a,b;
lll mini,a1,b1;
while(scanf("%I64d%I64d%I64d",&n,&a,&b)!=EOF)
{
mini = (1LL<<);
lll sum = (lll)*n;
for(lll i=a;i<=a+50000LL;i++)
{
lll tb = sum/i + (sum%i!=);
tb = max(b,tb);
lll tarea = i*tb;
if(tarea < mini)
{
mini = tarea;
a1 = i;
b1 = tb;
}
}
for(lll i=b;i<=b+50000LL;i++)
{
lll ta = sum/i + (sum%i!=);
ta = max(a,ta);
lll tarea = i*ta;
if(tarea < mini)
{
mini = tarea;
a1 = ta;
b1 = i;
}
}
cout<<mini<<endl<<a1<<" "<<b1<<endl;
}
return ;
}

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. PHP学习笔记:对命名空间(namespace)学习资料的翻译

    Name collisions means: you create a function named db_connect, and somebody elses code that you use ...

  2. Hibernate中的一级缓存、二级缓存和懒加载(转)

    1.为什么使用缓存 hibernate使用缓存减少对数据库的访问次数,从而提升hibernate的执行效率.hibernate中有两种类型的缓存:一级缓存和二级缓存. 2.一级缓存 Hibenate中 ...

  3. ahjesus ubuntu10.4安装ruby2.1.1

    sudo apt-get install python-software-properties sudo apt-add-repository ppa:brightbox/ruby-ng sudo a ...

  4. java.util.TimeZone 新加方法 getTimeZone(ZoneId zoneId) 导致的问题

    最近接受的项目中用spring配置了一个TimeZone对象: <bean id ="timeZone4Job" class="java.util.TimeZone ...

  5. VS 2013 Preview 自定义 SharePoint 2013 列表 之 两个Bug

    SharePoint 2013 已RTM了,对于程序员来说又要了解新功能了,同时 VS 2013 也将要 RTM了,两者同时应用定会有不新功能,我们先从 自定义 列表开始. SharePoint 20 ...

  6. 安卓开发--android library projects cannot be launched错误

    最新因为学习,问技术友要了几个源代码,导入源代码的时候无法进行真机或者虚拟机测试. 原因:android library projects cannot be launched 百度了一下,解决方法很 ...

  7. HorizontalScrollView实现先左滑动后右滑动动画

    @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); s ...

  8. Java从零开始学四十二(DOM解析XML)

    一.DOM解析XML xml文件 favorite.xml <?xml version="1.0" encoding="UTF-8" standalone ...

  9. windows 我的电脑右键 无法打开管理窗口

    保存成reg文件,执行一下就好了. Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069- ...

  10. 选择排序(java版)

    public class SelectSortTest { public static void selectSort(int[] source) { for (int i = 0; i < s ...