题意:给出一个两边长为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. java多线程(三)——锁机制synchronized(同步语句块)

    用关键字synchronized声明方法在某些情况下是有弊端的,比如A线程调用同步方法之行一个长时间的任务,那么B线程必须等待比较长的时间,在这样的情况下可以使用synchronized同步语句快来解 ...

  2. 一个小笔记(7):EN_1

    For nearly ten years, the Unified Modeling Language(UML) has been the industry standard for visualiz ...

  3. mariadb connector bug

    为了解决http://www.cnblogs.com/zhjh256/p/5807086.html的问题测试mariadb connector,常规的增删改查没有问题. 这货本来是为了解决存储过程bu ...

  4. .net mysql 支持表情

    1.表 utf8mb4 2.字段  utf8mb4 3.连接字符串 utf8mb4 4.存储过程参数  utf8mb4

  5. Python连接MySQL数据库

    连接MySQL数据库 源码: import MySQLdb #导入MySQLdb模块 print '连接数据库</br>' #连接MySQL数据库 connect the database ...

  6. SQL2012 提示评估已过期 解决方案- sql server问题

    SQL2012 提示评估已过期 解决方案提示评估已过期的解决方法和 sql2008一样 第1步:进入SQL2012配置工具中的安装中心第2步:再进入维护界面,选择版本升级第3步:进入产品密钥,输入密钥 ...

  7. UWP开发中的流媒体

    写这篇的目的只是为了记住这个东西, win10原生支持HLS了 AdaptiveMediaSourceCreationResult amsResult = await AdaptiveMediaSou ...

  8. Fragment官方解析

    由于fragment和activity的生命周期很类似,对activity不熟悉的可以参考–深入了解Activity-生命周期, 深入理解Activity-任务,回退栈,启动模式, 概要 A Frag ...

  9. android 小记

    1.INSTALL_FAILED_INSUFFICIENT_STORAGE 手机内存不够,删除部分后即可安装.

  10. Linux平台卸载MySQL总结【转】

    最近用到了mysql主从,顺手看到了这篇文章,拿出来分享一下. 转自:http://www.cnblogs.com/kerrycode/p/4364465.html 潇湘隐者 RPM包安装方式的MyS ...