我们不妨考虑可以划分为实数的情况,设划分为x份实数,使得总乘积最大。

易得当每一份都相等时乘积最大。即 ans=(n/x)^x. 现在只需要求出这个函数取得最大值的时候x的取值了。

两边取对数,则有ln(ans)=x*ln(n/x). 再两边取导数。可得当x=n/e的时候,每份是e的时候,总乘积最大。

那么现在考虑为整数的情况,由于3最接近e,则尽量将n分成每份为3.

那么现在就可以得出,当n%3==0时,分成n/3份3.

当n%3==1时,分成n/3-1份3和一份4.

当n%3==2时,分成n/3份3和一份2.

再结合高精度乘法即可求出答案。

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi 3.1415926535
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int res=, flag=;
char ch;
if((ch=getchar())=='-') flag=;
else if(ch>=''&&ch<='') res=ch-'';
while((ch=getchar())>=''&&ch<='') res=res*+(ch-'');
return flag?-res:res;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... struct BigInt{
const static int mod=;
const static int DLEN=;
int a[], len;
BigInt(){mem(a,); len=;}
BigInt(int v){
mem(a,); len=;
do{a[len++]=v%mod; v/=mod;}while(v);
}
BigInt operator*(const BigInt &b)const{
BigInt res;
FO(i,,len) {
int up=;
FO(j,,b.len) {
int temp=a[i]*b.a[j]+res.a[i+j]+up;
res.a[i+j]=temp%mod;
up=temp/mod;
}
if (up) res.a[i+b.len]=up;
}
res.len=len+b.len;
while (res.a[res.len-]==&&res.len>) res.len--;
return res;
}
void output(){
if (len<=) {
printf("%d",a[len-]);
for (int i=len-; i>=; --i) printf("%04d",a[i]);
putchar('\n');
}
else {
int x=a[len-], res=;
while (x) res++, x/=;
printf("%d",a[len-]);
for (int i=len-; i>len--(-res)/; --i) printf("%04d",a[i]);
if ((-res)%) {
int t=(-res)%, tmp=a[len--(-res)/];
FO(i,t,) tmp/=;
if (t==) printf("%d",tmp);
else if (t==) printf("%02d",tmp);
else printf("%03d",tmp);
}
}
}
int cal_len(){
int x=a[len-], res=;
while (x) res++, x/=;
return res+(len-)*;
}
};
BigInt ans;
int main ()
{
int n;
scanf("%d",&n);
ans=BigInt();
while (n>=) ans=ans*BigInt(), n-=;
if (n==) ans=ans*BigInt();
else ans=ans*BigInt(n);
printf("%d\n",ans.cal_len());
ans.output();
return ;
}

BZOJ 1263 整数划分(数学+高精度)的更多相关文章

  1. BZOJ 1263 整数划分

    Description 从文件中读入一个正整数\(n\).要求将\(n\)写成若干个正整数之和,并且使这些正整数的乘积最大. 例如,\(n=13\),则当\(n\)表示为\(4+3+3+3\)(或\( ...

  2. bzoj1263: [SCOI2006]整数划分(高精度+构造)

    第一次写压位高精度只好抄黄学长的 代码最后一段想了好久一看评论区才知道黄学长写错了= =很气 自己最后改对了T^T 这题最优是一直划分3出来直到<=4 #include<iostream& ...

  3. BZOJ 1263: [SCOI2006]整数划分( 高精度 )

    yy一下发现好像越小越好...分解成3*3*3*3……这种形式是最好的...然后就是高精度了 ----------------------------------------------------- ...

  4. [BZOJ1263][SCOI2006]整数划分(数学+高精度)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1263 分析:数学老师上课讲过啦= =,就是尽可能3越多越好.然后就写个高精度就行了.

  5. bzoj 3612 [Heoi2014]平衡——整数划分(dp)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3612 因为力矩的缘故,变成了整数划分. 学习到了整数划分.就是那个图一样的套路.https: ...

  6. bzoj 3612: [Heoi2014]平衡【整数划分dp】

    其实就是-n~n中求选k个不同的数,和为0的方案数 学到了新姿势叫整数划分,具体实现是dp 详见:https://blog.csdn.net/Vmurder/article/details/42551 ...

  7. BZOJ1263: [SCOI2006]整数划分

    1263: [SCOI2006]整数划分 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 677  Solved: 332[Submit][Status] ...

  8. 大概是:整数划分||DP||母函数||递推

    整数划分问题 整数划分是一个经典的问题. Input 每组输入是两个整数n和k.(1 <= n <= 50, 1 <= k <= n) Output 对于每组输入,请输出六行. ...

  9. 【题解】整数划分 [51nod1201] 整数划分 V2 [51nod1259]

    [题解]整数划分 [51nod1201] 整数划分 V2 [51nod1259] 传送门:整数划分 \([51nod1201]\) 整数划分 \(V2\) \([51nod1259]\)** [题目描 ...

随机推荐

  1. 从PRISM开始学WPF(七)MVVM(三)事件聚合器EventAggregator-更新至Prism7.1

    原文:从PRISM开始学WPF(七)MVVM(三)事件聚合器EventAggregator-更新至Prism7.1 事件聚合器EventAggregator [7.1updated]除了app部分,没 ...

  2. 《C++ Primer》第II部分:C++标准库

    <C++ Primer>第II部分:C++标准库 前言 把<C++ Primer>读薄系列笔记.本篇为第II部分C++标准库,包含全书第8-12章重难点: IO库 顺序容器 范 ...

  3. GitHub 配置指南

    Git和GitHub的区别 GitHub术语解析 配置使用 注册GitHub帐号 创建Git 创建库 复制库 社交化 Git和GitHub的区别 Git是一个分布式的版本控制系统,与SVN类似:最初由 ...

  4. PyYAML学习第一篇

    1. YAML是一种交互式和可读性强的脚本语言.脚本语言都是解释性语言. PyYAML是YAML语言的编辑器和解释器.在python语言里面有PyYAML的安装包. 相关学习文档:http://pyy ...

  5. 修改Eclipse中项目在Apache Tomcat中的部署路径

    在Eclipse中配项目已经部署到如下默认目录下:eclipse workspace/.metadata/.plugins/org.eclipse.core.resources/.projects. ...

  6. 编译Chromium出现warning C4819的解决办法

    编译Chromium时出现 warning C4819: The file contains a character that cannot be represented in the current ...

  7. MySQL☞lower函数

    lower(列名/字符串):将大写字母改成小写字母 格式: select  lower(列名/字符串)  from  表名 如下图:

  8. 巧用浏览器F12调试器定位系统前后端bug

    做测试的小伙伴可能用过httpwatch,firebug,fiddler,charles等抓包(数据包)工具,但实际上除了这些还有一个简单实用并的抓包工具,那就是浏览器的F12调试器. httpwat ...

  9. 第一篇 HTML基础

    浏览网页,就是上网,上网的本质就是下载内容. 浏览器是个解释器,用来执行HTML.css.JS代码的. HTML,CSS, JavaScript 号称网络三剑客. 1. 浏览器发送一个域名给服务端 2 ...

  10. Fiddler - 拦截手机请求

    1. 在电脑上安装Fillder. 安装好之后的Fiddler 打开是这样的: 2. 浏览器访问http://127.0.0.1:8888/fiddler,下载证书并安装 3. 打开抓取https请求 ...