zoukankan      html  css  js  c++  java
  • cf466B Wonder Room

    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 ≤ a1b ≤ 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
    %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
    %lld %lld",k,a,k/a);
    			else printf("%lld
    %lld %lld",k,k/a,a);
    			return 0;
    		}else k++;
    	}
    }
    

      

    ——by zhber,转载请注明来源
  • 相关阅读:
    Hibernate持久化对象修改id重新保存的办法
    hibernate实现数据实体复制保存
    MySQL 语句中执行优先级——and比or高
    Unity3D研究院之静态自动检查代码缺陷与隐患
    MVC模式在游戏开发的应用
    Unity3D的LightProbe动态光探头用法介绍
    高达渐出现效果Shader
    Unity3D战争迷雾效果
    从3D Studio Max导入物体 Importing Objects From 3D Studio Max
    从maya导入物体 Importing Objects From Maya
  • 原文地址:https://www.cnblogs.com/zhber/p/4035997.html
Copyright © 2011-2022 走看看