CF #266 (Div. 2) B
来源:互联网 发布:网络法制知识竞赛答题 编辑:程序博客网 时间:2024/05/06 14:53
B. Wonder Room
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
题目链接:http://codeforces.com/contest/466/problem/B
Input
The first line contains three space-separated integers n, a and b (1 ≤ n, a, b ≤ 109) — the number of students and the sizes of the room.
Output
Print three integers s, a1 and b1 (a ≤ a1; b ≤ b1) — the final area of the room and its sizes. If there are multiple optimal solutions, print any of them.
Sample test(s)
input
3 3 5
output
18
3 6
input
2 4 4
output
16
4 4
解题思路:
题目大意就是让你求a * b 的面积覆盖n * 6的面积,求最小的覆盖面积,输出时要求a <= a1 , b <= b1.
首先第一个坑······n ,a , b的范围······刚一个a * b 就有可能超过int······所以要开成__int64.
如果刚开始a * b的面积就大于n * 6,那么直接输出a * b 的面积和a、b的长度就好了;
否则的话分两种情况考虑。
当a <= b时,对a进行从a到sqrt(n * 6)的遍历,每次遍历求b' 时考虑奇偶数两种情况,当此时所求S大于n * 6 && 小于MIN && b' >= b时,进行更新;
同理当a > b 时,对b进行从b到sqrt(n * 6)的遍历,每次遍历求a' 时考虑奇偶两种情况,当此时所求S大于n * 6 && 小于MIN && a' >= a 时,进行更新;
完整代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef __int64 LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif LL n , a , b; while(~scanf("%I64d%I64d%I64d",&n,&a,&b)) { if(a * b >= n * 6) { printf("%I64d\n%I64d %I64d\n" , a * b , a , b); continue; } n = n * 6; LL x , y , MIN = INFF , s , j; if(a <= b) { for(LL i = a ; i <= sqrt(n) ; i++) { if(n % i == 0) { j = n / i; s = j * i; if(s >= n && s <= MIN && j >= b) { MIN = s; x = i; y = j; } } else { j = n / i + 1; s = i * j; if(s >= n && s <= MIN && j >= b) { MIN = s; x = i; y = j; } } } } else { for(LL i = b ; i <= sqrt(n) ; i ++) { if(n % i == 0) { j = n / i; s = i * j; if(s >= n && s <= MIN && j >= a) { MIN = s; y = i; x = j; } } else { j = n / i + 1; s = i * j; if(s >= n && s <= MIN && j >= a) { MIN = s; y = i; x = j; } } } } printf("%I64d\n%I64d %I64d\n" , MIN , x , y); }}
0 0
- CF #266 (Div. 2) B
- CF #230 (Div. 2) B
- CF #133(DIV.2) B
- CF #257 (Div. 2) B.
- CF#256 (Div. 2) B.
- CF#FF (Div. 2) B.
- CF#254 (Div. 2) B.
- CF#252 (Div. 2) B.
- CF#259 (Div. 2) B.
- CF#260 (Div. 2) B.
- CF #262 (Div. 2)B
- CF#261 (Div. 2) B
- CF #264 (Div. 2) B.
- CF #263 (Div. 2) B
- CF#258 (Div. 2) B
- CF#267 (Div. 2) B
- CF#269 (Div. 2) B
- cf 158div.2 B. Ancient Prophesy
- SE10与SE09有何区别?
- SQL Server附加数据库出错:无法打开物理文件,操作系统错误5
- 贝护佳孕妇客户端,笔记
- vs2013运行c语言出现:无法查找或打开 PDB 文件
- 【内核研究】理解Context
- CF #266 (Div. 2) B
- libcurl multi接口分析
- osg入门系列11- 预订义几何体
- 1.VC6.0致命错误 RC1015: 无法打开包含文件 'afxres.h'.解决方案
- 《数据结构》实验一:VC编程环境灵活应用
- 图片压缩算法(宽高不变)
- 运行一个EXE文件时,出现下面的文字,但程序能正常跑,请问怎么查找哪地方出现内存溢出?
- 【Python Challenge-6】zip
- 抽象方法不能是static或native或synchroniz 原因及误解