B. Wonder Room
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The start of the new academic year brought about the problem of accommodation students into dormitories. One of such dormitories has aa × b square meter wonder room. The caretaker wants to accommodate exactly n students there. But the law says that there must be at least 6 square meters per student in a room (that is, the room for n students must have the area of at least 6n square meters). The caretaker can enlarge any (possibly both) side of the room by an arbitrary positive integer of meters. Help him change the room so as all nstudents could live in it and the total area of the room was as small as possible.

Input

The first line contains three space-separated integers na and b (1 ≤ n, a, b ≤ 109) — the number of students and the sizes of the room.

Output

Print three integers sa1 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

第二题题意是有n*m的方格,可以增加n、m的值,但不能减少。要求使得(n')*(m')>=6k,求n' * m' 的最小值,及此时的n' * m'

以为是很厉害的数论……当时比赛中没想出来……后来写个爆搜竟然A了……后悔莫及

就是从6k开始判断可行性,不行就一直+1+1……

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#define LL long long
using namespace std;
LL n,m,k;
bool rev;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int main()
{
k=read();n=read();m=read();
if (n>m)swap(n,m),rev=1;
if (n*m>=6*k)
{
printf("%lld\n%lld %lld",n*m,n,m);
return 0;
}
k*=6;
while (1)
{
bool mrk=0;LL a=0;
for (int i=n;i<=sqrt(k);i++)
if (k%i==0&&k/i>=m)
{
mrk=1;
a=i;
break;
}
if (mrk)
{
if (!rev)printf("%lld\n%lld %lld",k,a,k/a);
else printf("%lld\n%lld %lld",k,k/a,a);
return 0;
}else k++;
}
}

  

cf466B Wonder Room的更多相关文章

随机推荐

  1. 关于WPF中承载 ArcGIS控件。

    原文 http://www.cnblogs.com/zoe-j/archive/2011/05/18/2050208.html 之前就做过WPF的应用,之前承载的MapGIS的二次开发控件,今天写一下 ...

  2. House Robber II 解答

    Question After robbing those houses on that street, the thief has found himself a new place for his ...

  3. C语言中不同类型的循环(Different types of loops in C)

    C语言中有三种类型的循环:for,while,do-while. while循环先判断循环条件. while (condition) { //gets executed after condition ...

  4. linux 安装gcc和g++

    linux中安装gcc和g++ 今天在linux的服务器上安装C/C++的编译器gcc和g++,运行了如下两条命令: 1 yum install gcc yum install g++ 然后发现gcc ...

  5. 关于 require的缓存

    有两个文件 a.js内容如下: var add = require("./t.js").add; var add2 = require("./t.js").ad ...

  6. Longest Palindromic Substring-----最长回文子串

    首先讲讲什么是回文, 看看Wiki是怎么说的:回文,亦称回环,是正读反读都能读通的句子.亦有将文字排列成圆圈者,是一种修辞方式和文字游戏.回环运用得当.能够表现两种事物或现象相互依靠或排斥的关系, 比 ...

  7. 大话NoSql

    之前看过一本名叫<<大数据挑战的书>>.里面主要讲了NOSQL的内容,感觉讲得确实不错,今天来又一次温习一下,我们大话NOSQL.说道NOSQL.我们肯定联想到的内容就是Big ...

  8. 加载本地html遇到的问题

    之前要做一个Demo,需要用UIWebView来加载网页,前端的同事把资源包给我,里面包含html,css,JavaScript,图片等文件.我想当然的把文件夹拷到工程中,然后用以下方法加载: NSU ...

  9. MySQL中innodb表主键设计原则

    主键设计的原则:1. 一定要显式定义主键2. 采用与业务无关的单独列3. 采用自增列4. 数据类型采用int,并尽可能小,能用tinyint就不用int,能用int就不用bigint5. 将主键放在表 ...

  10. .Net 中DataSet导出为excel的方法

    依旧是留下代码防止以后忘记 protected void Export_Click(object sender, EventArgs e) { DataSet data = "" ...