我们不妨考虑可以划分为实数的情况,设划分为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-9
# define MOD 100000007
# define INF 1000000000
# 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<<1,l,mid
# define rch p<<1|1,mid+1,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=0, flag=0;char ch;if((ch=getchar())=='-') flag=1;else if(ch>='0'&&ch<='9') res=ch-'0';while((ch=getchar())>='0'&&ch<='9')  res=res*10+(ch-'0');return flag?-res:res;
}
void Out(int a) {if(a<0) {putchar('-'); a=-a;}if(a>=10) Out(a/10);putchar(a%10+'0');
}
const int N=5005;
//Code begin...struct BigInt{const static int mod=10000;const static int DLEN=4;int a[1500], len;BigInt(){mem(a,0); len=1;}BigInt(int v){mem(a,0); len=0;do{a[len++]=v%mod; v/=mod;}while(v);}BigInt operator*(const BigInt &b)const{BigInt res;FO(i,0,len) {int up=0;FO(j,0,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-1]==0&&res.len>1) res.len--;return res;}void output(){if (len<=24) {printf("%d",a[len-1]);for (int i=len-2; i>=0; --i) printf("%04d",a[i]);putchar('\n');}else {int x=a[len-1], res=0;while (x) res++, x/=10;printf("%d",a[len-1]);for (int i=len-2; i>len-2-(100-res)/4; --i) printf("%04d",a[i]);if ((100-res)%4) {int t=(100-res)%4, tmp=a[len-2-(100-res)/4];FO(i,t,4) tmp/=10;if (t==1) printf("%d",tmp);else if (t==2) printf("%02d",tmp);else printf("%03d",tmp);}}}int cal_len(){int x=a[len-1], res=0;while (x) res++, x/=10;return res+(len-1)*4;}
};
BigInt ans;
int main ()
{int n;scanf("%d",&n);ans=BigInt(1);while (n>=6) ans=ans*BigInt(3), n-=3;if (n==5) ans=ans*BigInt(6);else ans=ans*BigInt(n);printf("%d\n",ans.cal_len());ans.output();return 0;
}

View Code

转载于:https://www.cnblogs.com/lishiyao/p/6549939.html

BZOJ 1263 整数划分(数学+高精度)相关推荐

  1. bzoj 1263: [SCOI2006]整数划分

    1263: [SCOI2006]整数划分 Time Limit: 1 Sec  Memory Limit: 162 MB Submit: 1449  Solved: 736 [Submit][Stat ...

  2. 整数划分 --- 一个老生长谈的问题 动态规划

    整数划分 --- 一个老生长谈的问题: 1) 练练组合数学能力. 2) 练练递归思想 3) 练练DP 总之是一道经典的不能再经典的题目: 这道好题求: 1. 将n划分成若干正整数之和的划分数. 2. ...

  3. 整数划分c语言程序递归,递归整数划分

    递归实现整数划分 目录 递归实现整数划分 1.原理 2.Python实现 3.C实现 1.原理 拿6为例,可划分为: 6 5+1 4+2 4+1+1 3+3 3+2+1 3+1+1+1 2+2+2 2 ...

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

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

  5. C语言接收一个整数划分成5的倍数,整数划分为连续整数;整数划分

    参考博客:http://www.cnblogs.com/nokiaguy/archive/2008/05/11/1192308.html 1.整数划分为连续整数: 如将15划分为连续整数之和: 15 ...

  6. 51nod 1201:整数划分 超级好的DP题目

    1201 整数划分 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  关注 将N分为若干个不同整数的和,有多少种不同的划分方式,例如:n = 6,{6} { ...

  7. linux+shell+整数计算器,Shell(())实现对整数进行数学运算

    双小括号 (( )) 是 Bash Shell 中专门用来进行整数运算的命令,它的效率很高,写法灵活,是企业运维中常用的运算命令. 注意:(( )) 只能进行整数运算,不能对小数(浮点数)或者字符串进 ...

  8. 算法笔记——整数划分1

    题目来源:NYOJ90 问题描述: 将正整数n表示成一系列正整数之和:n=n1+n2+-+nk, 其中n1≥n2≥-≥nk≥1,k≥1. 正整数n的这种表示称为正整数n的划分.求正整数n的不 同划分个 ...

  9. Acwing900. 整数划分[计数类dp]:完全背包解法

    文章目录 题目分析 完全背包解法 题目链接 题目分析 完全背包解法 请复习完全背包模板完全背包dp优化内有完整标准完全背包的推导过程 状态表示: f[i][j]f[i] [j]f[i][j] 表示从 ...

最新文章

  1. 执行umount 的时候却提示:device is busy 的处理方法
  2. 周五话分析 | 共享单车起航,数据分析跟上
  3. C语言#define预处理
  4. zookeeper系列之通信模型(转)
  5. 微软修复严重的Azure漏洞,可用于泄露客户数据
  6. input正则邮箱_javascript写一个校验邮箱的正则表达式
  7. oracle 进入empt,关于redhat6.2静默安装oracle11g出现的问题 大神救命
  8. 服务器怎么设置虚拟网卡,VMWare虚拟网卡配置
  9. web前端顶岗实习总结报告_web前端实习报告
  10. cuda历史版本下载
  11. pythonnumpy矩阵详解_基于Python Numpy的数组array和矩阵matrix详解_python
  12. torch.autograd.grad求二阶导数
  13. 用 M1 MacBook 当主力开发机:程序员使用半个月后如是说
  14. 你三十岁的生日,我写文章纪念 (西祠旧贴)
  15. 百度前端训练营day2笔记
  16. d va爬黑板animate_部编版四年级语文上册第17课爬天都峰微课视频|MP3朗读|同步练习...
  17. 一个想让你承认是Gay的“勒索版”远控木马Swamp分析
  18. WordPress常见问题及其解决方法
  19. JMeter基础使用教程及使用技巧(快速入门)
  20. 反光柱建图和定位总结

热门文章

  1. 边缘AI计算新时代,人工神经网络秒变脉冲神经网络
  2. PyTorch | 通过torch.normal()创建概率分布的张量 | torch.normal()如何使用?torch.normal()使用方法 | torch.normal()例子
  3. 不再遥不可及!盘点独角兽自动驾驶战略
  4. OCR文本检测-RRPN
  5. Python中的random库
  6. c++语言int最大值,c++ 关于如何获取int型的最大值
  7. mysql自动定时备份数据,mysql数据库自动定时备份脚本
  8. 安全狗导致php错误,服务器安全狗导致ASP.NET网站运行出错的一个案例
  9. java nslookup_nslookup使用教程
  10. java类型之间的转换_JAVA基本数据类型及之间的转换