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)),那么我们可以枚举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 --枚举的更多相关文章
- Codeforces Round #266 (Div. 2)B(暴力枚举)
很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实. 两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质. 这道题找 ...
- Codeforces Round #266 (Div. 2)
http://codeforces.com/contest/466 噗,b没写出来啊.a写完后过了40分钟了啊,罚时4次啊!果然太弱 总结: a题看错题,没有考虑m>=n其实也是可行的,导致调了 ...
- Codeforces Round #266 (Div. 2) D
D. Increase Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #266 (Div. 2)-C,D
C - Number of Ways 直接暴力从前往后寻找.假设找到1/3sum的位置,那么标记++.找到2/3的位置,总数加上标记数. #include<stdio.h> #includ ...
- 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 ...
- Codeforces Round #249 (Div. 2) D. Special Grid 枚举
题目链接: http://codeforces.com/contest/435/problem/D D. Special Grid time limit per test:4 secondsmemor ...
- Codeforces Round #422 (Div. 2) B. Crossword solving 枚举
B. Crossword solving Erelong Leha was bored by calculating of the greatest common divisor of two ...
- Codeforces Round #666 (Div. 2) B. Power Sequence (枚举)
题意:有一个长度为\(n\)的序列,你每次可以对序列重新排序,然后花费\(1\)使某个元素加减\(1\),多次操作后使得新序列满足\(a_{i}=c^i\),\(c\)是某个正整数,求最小花费. 题解 ...
- Codeforces Round #669 (Div. 2) B. Big Vova (枚举)
题意:有一个长度为\(n\)的序列,你需要对其重新排序,构造一个新数组\(c\),\(c_{i}=gcd(a_{1},...,a{i})\)并且使得\(c\)的字典序最小. 题解:直接跑\(n\)次, ...
随机推荐
- 【Asphyre引擎】学习笔记(二)
转一篇火人论坛那边的一份学习文档,我简单排一下版,希望对入门者有帮助. 感谢China Yang,这份文档也帮助我快速入了门. 和我一起学 Asphyre Sphinx Framework v1.0. ...
- 静态导入Static import
静态导入Static import 要使用静态成员(方法和变量)我们必须给出提供这个静态成员的类. 使用静态导入可以使被导入类的静态变量和静态方法在当前类直接可见,使用这些静态成员无需再给出他们的类名 ...
- 详解;(function ($,window,document,undefined){...})(jQuery,window,document);
1.代码最前面的分号,可以防止多个文件压缩合并以为其他文件最后一行语句没加分号,而引起合并后语法错误. 2.匿名函数(function(){})();:由于Javascript执行表达式是从圆括号里面 ...
- File类的常用方法
public static void GetFileInfo() { File file=new File("e:","two.txt ...
- Lucene总体架构
Lucene总的来说是:• 一个高效的,可扩展的,全文检索库.• 全部用Java实现,无须配置.• 仅支持纯文本文件的索引(Indexing)和搜索(Search).• 不负责由其他格式的文件抽取纯文 ...
- 简单认识UISwitch
以下是常用属性: self.mySwitch.layer.cornerRadius = 15; // 边框圆角角度 self.mySwitch.layer.borderWidth = 2; // ...
- 多线程基础(二)pthread的了解
IOS中多线程的实现方案 了解NSOperation(代码) 所有的方法都是pthread开头的 然后再搞一条线程 pthread_create方法有返回值,作用:判断线程创建是否成功? ...
- 设置IE兼容模式的几种方法
一.指定文件兼容性模式要为你的网页指定文件模式,需要在你的网页中使用meta元素放入x-ua-compatible http-equiv 标头.1. 强制ie8使用ie8模式来解析,而且那个兼容性视图 ...
- 【mysql】关于临时表
mysql官方的介绍 In some cases, the server creates internal temporary tables while processing queries. Suc ...
- Spring4定时器 cronTrigger和simpleTrigger实现方法
spring4定时器 cronTrigger和simpleTrigger实现方法 Quartz 是个开源的作业调度框架,为在 Java 应用程序中进行作业调度提供了简单却强大的机制.Quartz 允许 ...