codeforces163D
Large Refrigerator
给定一个长方体的体积V,求出这个长方体的最小表面积。
输入
第一行有一个整数t (1 ≤ t ≤ 500) — 测试数据的组数。
下面是t组测试数据。每一组表示一个整数V (2 ≤ V ≤ 1018),通过分解质因数的形式给出。
设V = p1a1p2a2... pkak,其中pi 是不同的素数,ai是正整指数。
第一行给出一个正整数k — V中不同的质因子的个数。下面k行每行两个数字:pi和ai,用空格隔开。每一个pi都是不同的。所有ai > 0。
输出
输出t 行,在第i行输出第i-组测试数据的答案,其中包含4个空格隔开的数:最小表面积S和对应的长宽高的长度a,b,c。如果有多个答案,输出任意。长宽高顺序没有规定。
样例
3
1
2 3
1
17 1
3
3 1
2 3
5 1
24 2 2 2
70 1 1 17
148 4 6 5
注释
在第一个测试数据中体积V = 23 = 8,最小表面积可由三边相等的正方体构成。
在第二个测试数据中体积V = 17,该长方体只有一种构成方法。
sol:直接爆搜会T出屎,所以要剪枝,我就XJB剪了一下,先搜a再搜b,强制a<b<c,还有中间如果体积已经超出了就退出,然后就过了
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
const ll inf=0x7fffffffffffffffll;
int T,n,tot=;
struct Node
{
ll p,a;
inline bool operator<(const Node &tmp)const
{
return p<tmp.p;
}
}Num[N];
ll P[N],A[N],V,ans,aa,bb,cc;
inline ll Ksm(ll x,ll y)
{
ll Res=;
while(y)
{
if(y&) Res=1ll*Res*x; x=1ll*x*x; y>>=;
}
return Res;
}
inline bool Judge(ll a)
{
return (1ll*(sqrt(V/a)**a+V/a)<=ans);
}
inline void dfs(int Now,ll a);
inline void dfs1(int Now,ll a,ll b);
inline void dfs(int Now,ll a)
{
if(a*a*a>V) return;
if(Now==n+)
{
if(Judge(a)) dfs1(,a,);
return;
}
int i;
ll tmp=Ksm(P[Now],A[Now]);
for(i=A[Now];i>=;i--)
{
A[Now]-=i;
dfs(Now+,a*tmp);
A[Now]+=i;
tmp/=P[Now];
}
dfs(Now+,a);
}
inline void dfs1(int Now,ll a,ll b)
{
if(a*b*b>V) return;
if(Now==n+)
{
ll c=V/a/b,tmp; tmp=a*b+a*c+b*c;
if(tmp<ans)
{
ans=tmp; aa=a; bb=b; cc=c;
}
return;
}
int i;
ll tmp=Ksm(P[Now],A[Now]);
for(i=A[Now];i>=;i--)
{
A[Now]-=i;
dfs1(Now+,a,b*tmp);
A[Now]+=i;
tmp/=P[Now];
}
dfs1(Now+,a,b);
}
int main()
{
int i;
R(T);
while(T--)
{
V=; ans=inf; R(n); tot=;
for(i=;i<=n;i++)
{
R(Num[++tot].p); R(Num[tot].a); V*=Ksm(Num[tot].p,Num[tot].a);
}
sort(Num+,Num+tot+);
for(i=;i<=tot;i++) {P[i]=Num[i].p; A[i]=Num[i].a;}
dfs(,);
W(1ll*ans*); W(aa); W(bb); Wl(cc);
}
return ;
}
/*
Input
4
1
2 3
1
17 1
3
3 1
2 3
5 1
1
2 2
Output
24 2 2 2
70 1 1 17
148 4 6 5
16 2 2 1 input
3
4
208513 1
2 1
10753058401 1
223 1
4
17469877 1
1283 1
949261 1
47 1
4
313 1
2 1
1546412477693 1
1033 1
output
4493896846822714 446 208513 10753058401
35388330702870 60301 949261 17469877
5130996602278690 626 1033 1546412477693
*/
codeforces163D的更多相关文章
随机推荐
- pt-table-checksum和pt-table-sync使用
pt-table-checksum和pt-table-sync使用 数据库版本:5.6.25 pt工具版本:2.2.14 主从关系一:不同机器同一端口 10.10.228.163:4306(rescs ...
- 第十二章 ZYNQ-MIZ702 PS读写PL端BRAM
本篇文章目的是使用Block Memory进行PS和PL的数据交互或者数据共享,通过zynq PS端的Master GP0端口向BRAM写数据,然后再通过PS端的Mater GP1把数据读出来,将 ...
- kubernetes kubeadm安装v1.14
1.我们这里准备两台Centos7的主机用于安装,后续节点可以根究需要添加即可:master node01两台都得改:cat /etc/hosts192.168.71.134 master192.16 ...
- 使用 js 简单的实现 bind、call 、aplly
Function.prototype._call = function(obj,...arg){ var me = this; var k = Symbol("test"); // ...
- Java写学生管理系统
package Homework08;/*调试了一上午,收获:学会了昨天的debug的使用吸取教训:Student stus[]=new Student[2]; for (int i=0;i<s ...
- npm无法安装node-sass的解决方法
使用npm install 命令安装node-sass时,经常出现安装失败的情况.原因在于npm服务器在美国,还有就是某强大的防火墙作用.导致模块无法下载. npm install node-sass ...
- 【温故知新】php 魔术方法
<?php class Magic{ private $name; /** *构造方法,在类被实例化时自动调用,一般用于初始化操作 */ public function __construct( ...
- WPF实战案例-在线程内同步集合数据到UI线程
有这样一个场景,在vm中,我们为了ui的体验,会异步访问后端接口,获取数据集合,如果这个集合绑定到界面,并且在线程内,怎么处理? 有人讲:this.Dispatcher.Invoke,如果在vm内呢? ...
- Image Processing and Computer Vision_Review:Recent Advances in Features Extraction and Description Algorithms: A Comprehensive Survey——2017.03
翻译 特征提取和描述算法的最新进展:全面的调查 摘要 - 计算机视觉是当今信息技术中最活跃的研究领域之一.让机器和机器人能够以视线的速度看到和理解周围的世界,创造出无穷无尽的潜在应用和机会.特征检测和 ...
- 《数字图像处理(MATLAB)》冈萨雷斯
<数字图像处理(MATLAB)>冈萨雷斯 未完结! 参考:数字图像处理——https://blog.csdn.net/dujing2019/article/category/8820151 ...