Codeforces Round #266 (Div. 2)B(暴力枚举)
很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实。
两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质。
这道题找出a和b中最小的那个,然后开始枚举,一直枚举到sqrt(6*n)的向上取整。这样所有可能是答案的情况都有啦。再干别的都是重复的或者肯定不是最小面积的。
- #include<iostream>
- #include<cstdio>
- #include<cstdlib>
- #include<cstring>
- #include<cmath>
- #include<map>
- #include<set>
- #include<vector>
- #include<algorithm>
- #include<stack>
- #include<queue>
- #include<cctype>
- #include<sstream>
- using namespace std;
- #define INF 1000000000
- #define eps 1e-8
- #define pii pair<int,int>
- #define LL long long int
- LL a,b,n,s,a1,b1,t;
- int main()
- {
- //freopen("in8.txt","r",stdin);
- //freopen("out.txt","w",stdout);
- scanf("%I64d%I64d%I64d",&n,&a,&b);
- s=;
- t=ceil(sqrt(*n));
- LL sum=*n;
- if(n*<=a*b)
- cout<<a*b<<endl<<a<<' '<<b<<endl;
- else
- {
- bool c=;
- if(a>b)
- {
- c=;
- swap(a,b);
- }
- for(LL i=a;i<=t;i++)
- {
- LL t=max(b,sum/i+(sum%i!=));
- if(i*t<s)
- {
- a1=i,b1=t,s=i*t;
- }
- }
- if(c)
- cout<<s<<endl<<b1<<' '<<a1<<endl;
- else
- cout<<s<<endl<<a1<<' '<<b1<<endl;
- }
- //fclose(stdin);
- //fclose(stdout);
- return ;
- }
Codeforces Round #266 (Div. 2)B(暴力枚举)的更多相关文章
- Codeforces Round #253 (Div. 2)B(暴力枚举)
就暴力枚举所有起点和终点就行了. 我做这题时想的太多了,最简单的暴力枚举起始点却没想到...应该先想最简单的方法,层层深入. #include<iostream> #include< ...
- Codeforces Round #258 (Div. 2)C(暴力枚举)
就枚举四种情况,哪种能行就是yes了.很简单,关键是写法,我写的又丑又长...看了zhanyl的写法顿时心生敬佩.写的干净利落,简直美如画...这是功力的体现! 以下是zhanyl的写法,转载在此以供 ...
- 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 ...
- Codeforces Round #266 (Div. 2)
http://codeforces.com/contest/466 噗,b没写出来啊.a写完后过了40分钟了啊,罚时4次啊!果然太弱 总结: a题看错题,没有考虑m>=n其实也是可行的,导致调了 ...
- 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 ...
- 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 ...
- 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 #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 ...
随机推荐
- Link
GNU/Linux, Bash, C, PHP, Perl, JavaScript, Vim, Git http://blog.sanctum.geek.nz/about 中文數學詞典 http: ...
- JS字符串数组转换
字符串转数组: str.split(';') 数组转字符串: arr.join(';')
- Linux基本命令 vim命令(一)
vim的三种工作模式 命令模式.输入模式和编辑模式的相互转换,如图 命令模式:使用 Vim 编辑文件时,默认处于命令模式.在此模式下,可以使用上.下.左.右键或者 k.j.h.l 命令进行光标移动,还 ...
- CSS伪元素实现的3D按钮
在线演示 本地下载
- python:字典的方法
1.查找字典中的key对应的值和key是否存在(get,has_key)dict.get(key, default = None) :返回字典中key对应的值,若key不存在字典中,则返回defaul ...
- Centos6.5下ElasticSearch1.4.4的安装
1.下载ElasticSearch 官网地址 https://www.elastic.co/ 2.安装elasticsearch-1.4.4.tar.gz tar -zxvf elasticsearc ...
- [转载]Google Android开发精华教程
原文地址:Android开发精华教程">Google Android开发精华教程作者:huiyi8zai Android是Google于2007年11月5日宣布的基于Linux平台的开 ...
- wareshark网络协议分析之DHCP
声明:本文关于DHCP协议介绍部分摘自百度百科 一.DHCP协议介绍: DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)是一个局域网的网络协议,使用 ...
- QT5中如何使用QFtp类
QT5中如何使用QFtp类 http://2662597.blog.51cto.com/2652597/1279806 由于QT5对QML的支持有很大的改进,所以打算将原来基于QT4的程序移植到QT5 ...
- svg_鼠标手型
1. 貌似是 属性 "cursor :pointer;",待测试. 2.