CF163D Large Refrigerator

题目描述

Vasya wants to buy a new refrigerator. He believes that a refrigerator should be a rectangular parallelepiped with integer edge lengths. Vasya calculated that for daily use he will need a refrigerator with volume of at least V V V . Moreover, Vasya is a minimalist by nature, so the volume should be no more than V V V , either — why take up extra space in the apartment? Having made up his mind about the volume of the refrigerator, Vasya faced a new challenge — for a fixed volume of V V V the refrigerator must have the minimum surface area so that it is easier to clean.

The volume and the surface area of a refrigerator with edges a a a , b b b , c c c are equal to V=abc V=abc V=abc and S=2(ab+bc+ca) S=2(ab+bc+ca) S=2(ab+bc+ca) , correspondingly.

Given the volume V V V , help Vasya find the integer lengths for the refrigerator's edges a a a , b b b , c c c so that the refrigerator's volume equals V V V and its surface area S S S is minimized.

输入输出格式

输入格式:

The first line contains a single integer t t t ( 1<=t<=500 1<=t<=500 1<=t<=500 ) — the number of data sets.

The description of t t t data sets follows. Each set consists of a single integer V V V ( 2<=V<=1018 2<=V<=10^{18} 2<=V<=1018 ), given by its factorization as follows.

Let V V V = p1a1p2a2... pkak p_{1}^{a_{1}}p_{2}^{a_{2}}...\ p_{k}^{a_{k}} p1a1p2a2... pkak , where pi p_{i} pi are different prime numbers and ai a_{i} ai are positive integer powers.

Then the first line describing a data set contains a single positive integer k k k — the number of different prime divisors of V V V . Next k k k lines contain prime numbers pi p_{i} pi and their powers ai a_{i} ai , separated by spaces. All pi p_{i} pi are different, all $ a_{i}&gt;0 $ .

输出格式:

Print t t t lines, on the i i i -th line print the answer to the i i i -th data set as four space-separated integers: the minimum possible surface area S S S and the corresponding edge lengths a a a , b b b , c c c . If there are multiple variants of the lengths of edges that give the minimum area, you are allowed to print any of them. You can print the lengths of the fridge's edges in any order.

输入输出样例

输入样例#1: 复制
3
1
2 3
1
17 1
3
3 1
2 3
5 1
输出样例#1: 复制
24 2 2 2
70 1 1 17
148 4 6 5

说明

In the first data set of the sample the fridge's volume V=23=8 V=2^{3}=8 V=23=8 , and the minimum surface area will be produced by the edges of equal length.

In the second data set the volume V=17 V=17 V=17 , and it can be produced by only one set of integer lengths.

题解

a &lt; = b &lt; = c a&lt;=b&lt;=c a<=b<=c
所以有 a &lt; = V 3 a&lt;=\sqrt[3]{V} a<=3V
然后 b c = V a bc=\frac{V}{a} bc=aV
由均值不等式 b + c &lt; = 2 V a b+c&lt;=2\sqrt{\frac{V}{a}} b+c<=2aV
所以 S m i n = 2 ( a b + b c + a c ) = 2 ( a ( b + c ) + b c ) = 2 ( a ∗ 2 V a + V a ) = 4 a V a + 2 V a S_{min}=2(ab+bc+ac)=2(a(b+c)+bc)=2(a*2\sqrt{\frac{V}{a}}+\frac{V}{a})=4a\sqrt{\frac{V}{a}}+2\frac{V}{a} Smin=2(ab+bc+ac)=2(a(b+c)+bc)=2(a2aV +aV)=4aaV +2aV
由于 b b b c c c为整数,结果可能大于 S m i n S_{min} Smin,利用这个性质,可以进行剪枝。

具体实现:
我们枚举 a a a,将现有最小值和期望最小值进行比较
若现有最小值 &lt; = &lt;= <=期望最小值, 则可以剪枝。
再用一个 d f s dfs dfs求出 b b b c c c即可。

这个精度比较坑人,需要 d o u b l e double double

#include <bits/stdc++.h>
#define MOD
#define MAXN 505
#define MAXM
#define LL long long
#define ll long long
#define mem(a) memset(a,0,sizeof(a))
#define memmax(a) memset(a,0x3f,sizeof(a))
#define int long long
using namespace std;
inline int read(){
	int 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 Pow[25][MAXN],n,V,ans,B;
int val[MAXN];
void dfs2(int i,int b,int a){//求maxb 
	if ((double)b*b>V/a){//保证b<=c 
		return ;
	}
	if (i>n){
		B=max(B,b);
		return ;
	}
	for (register int j=val[i];j>=0;--j){
		dfs2(i+1,b*Pow[i][j],a);
	}
}
int ansA,ansB,ansC;
void dfs1(int i,int a){//求a 
	if ((double)a*a*a>V){
		return ;
	}
	if (i>n){
		const int t=V/a;
		int Smax=4*a*sqrt(t)+2*t;//期望最大值 
		if (Smax>=ans) return ;//最优性剪枝
		B=0,dfs2(1,1,a);
		int c=V/a/B,Ans=(a*B+B*c+c*a)<<1;
		if (Ans<ans){
			ans=Ans;
			ansA=a,ansB=B,ansC=c;
		}
		return ;
	}
	for (register int j=val[i];j>=0;--j){
		val[i]-=j;
		dfs1(i+1,a*Pow[i][j]);
		val[i]+=j;
	}
}
#undef int
int main(){
#define int long long
    int T;
	cin>>T;
	while (T--){
		cin>>n;
		V=1;
		for (register int i=1;i<=n;++i){
		    int a,b;
			cin>>a>>b;
			val[i]=b;
			Pow[i][0]=1;
			for (register int j=1;j<=b;++j){
				Pow[i][j]=Pow[i][j-1]*a;
			}
			V*=Pow[i][b];
		}
		ans=1ll<<62;
		dfs1(1,1);
		cout<<ans<<" "<<ansA<<" "<<ansB<<" "<<ansC<<endl;
	}
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
商业制冷柜是指专门为商业使用而设计的制冷设备,用于存储和保鲜食品和饮料。亚美尼亚的商业制冷柜市场也在不断发展和壮大。 商业制冷柜在餐饮行业中扮演着重要角色。许多餐厅、咖啡馆、超市和其他食品销售点都需要商业制冷柜来储存和展示食品和饮料。商业制冷柜通常具有更大的存储能力和更强大的制冷能力,以应对商业场景中的高需求。它们通常由高效的制冷系统、保温玻璃门和定制的存储区域组成,以确保食品能够保持新鲜和安全。 亚美尼亚的商业制冷柜市场在近年来经历了快速增长。随着亚美尼亚经济的发展和人们对饮食品质的要求提高,餐饮行业的需求也在增加。这导致了商业制冷柜的需求的增加。亚美尼亚的制冷设备市场已经出现了多家制冷柜制造商和供应商,提供各种类型和规格的商业制冷柜以满足不同商家的需求。 商业制冷柜的发展对亚美尼亚经济产生了积极的影响。它不仅提供了就业机会,还促进了食品销售和餐饮行业的增长。商业制冷柜的使用可以帮助商家提高食品的质量和保鲜度,增强顾客对商家的信任和忠诚度。 总的来说,商业制冷柜在亚美尼亚是一个重要且不断发展的市场。它的存在和发展为亚美尼亚的餐饮行业和食品销售提供了重要的支持,并对亚美尼亚的经济增长做出了贡献。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值