cf466B Wonder Room
1 second
256 megabytes
standard input
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.
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.
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.
3 3 5
18
3 6
2 4 4
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的更多相关文章
随机推荐
- NFC应用(二)读写器模式
NFC第二种应用场境就是所谓的读写器模式.既然有卡,当然就会有读写器,这两种模式是配合在一起使用的.两个卡放一起不能通信,两个读写器模式的设备也不能通信. NFC读写器一般支持以下一种或多种协议:Mi ...
- C语言的本质(38)——makefile之变量
我们详细看看Makefile中关于变量的语法规则.先看一个简单的例子: foo = $(bar) bar = Huh? all: @echo$(foo) 我们执行make将会打出Huh?.当make读 ...
- 【Shell脚本】运行shell脚本文件的几种方法与区别
Shell脚本不同的运行方式会对当前Shell设置或者运行结果有所不同. 假设现在有一个脚本名为display_shell_script_args.sh,其内容如下: #!/home/pyf/bin/ ...
- JavaScript中setTimeout()和setInterval()的区别
含义: setTimeout()和setInterval()经常被用来处理延时和定时任务.使用setTimeout()处理延时任务,而使用setInterval()方法处理定时任务: setTimeo ...
- python分布式抓取网页
呵呵,前两节好像和python没多大关系..这节完全是贴代码, 这是我第一次写python,很多地方比较乱,主要就看看逻辑流程吧. 对于编码格式确实搞得我头大..取下来页面不知道是什么编码,所以先找c ...
- hdu 5625 Clarke and chemistry
Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned i ...
- android ANR 案例分析
案例1:关键词:ContentResolver in AsyncTask onPostExecute, high iowait Process:com.android.email Activity:c ...
- iOS动画一点也不神秘————你是喜欢看幻灯片?还是看高清电影?
iOS设备在平均线上硬件比andorid设备良好许多,尤其是内存和CPU,所以iOS应用里面有大量动画交互效果的交互,这是每个用户都喜悦的,如果每个操作对应界面来讲都是直接变化,那变得十分地生硬. 你 ...
- C#关于params的用法(使用数量可变的参数)
有些方法需要传递个数不定的值进行运算.比如求最小值的方法.除了用容器外,还可以使用params来做 例子如下: using System; using System.Collections.Gener ...
- js库开发--参数传递及方法修改
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> ...