我们不妨考虑可以划分为实数的情况,设划分为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.

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

  1. # include <cstdio>
  2. # include <cstring>
  3. # include <cstdlib>
  4. # include <iostream>
  5. # include <vector>
  6. # include <queue>
  7. # include <stack>
  8. # include <map>
  9. # include <set>
  10. # include <cmath>
  11. # include <algorithm>
  12. using namespace std;
  13. # define lowbit(x) ((x)&(-x))
  14. # define pi 3.1415926535
  15. # define eps 1e-
  16. # define MOD
  17. # define INF
  18. # define mem(a,b) memset(a,b,sizeof(a))
  19. # define FOR(i,a,n) for(int i=a; i<=n; ++i)
  20. # define FO(i,a,n) for(int i=a; i<n; ++i)
  21. # define bug puts("H");
  22. # define lch p<<,l,mid
  23. # define rch p<<|,mid+,r
  24. # define mp make_pair
  25. # define pb push_back
  26. typedef pair<int,int> PII;
  27. typedef vector<int> VI;
  28. # pragma comment(linker, "/STACK:1024000000,1024000000")
  29. typedef long long LL;
  30. int Scan() {
  31. int res=, flag=;
  32. char ch;
  33. if((ch=getchar())=='-') flag=;
  34. else if(ch>=''&&ch<='') res=ch-'';
  35. while((ch=getchar())>=''&&ch<='') res=res*+(ch-'');
  36. return flag?-res:res;
  37. }
  38. void Out(int a) {
  39. if(a<) {putchar('-'); a=-a;}
  40. if(a>=) Out(a/);
  41. putchar(a%+'');
  42. }
  43. const int N=;
  44. //Code begin...
  45.  
  46. struct BigInt{
  47. const static int mod=;
  48. const static int DLEN=;
  49. int a[], len;
  50. BigInt(){mem(a,); len=;}
  51. BigInt(int v){
  52. mem(a,); len=;
  53. do{a[len++]=v%mod; v/=mod;}while(v);
  54. }
  55. BigInt operator*(const BigInt &b)const{
  56. BigInt res;
  57. FO(i,,len) {
  58. int up=;
  59. FO(j,,b.len) {
  60. int temp=a[i]*b.a[j]+res.a[i+j]+up;
  61. res.a[i+j]=temp%mod;
  62. up=temp/mod;
  63. }
  64. if (up) res.a[i+b.len]=up;
  65. }
  66. res.len=len+b.len;
  67. while (res.a[res.len-]==&&res.len>) res.len--;
  68. return res;
  69. }
  70. void output(){
  71. if (len<=) {
  72. printf("%d",a[len-]);
  73. for (int i=len-; i>=; --i) printf("%04d",a[i]);
  74. putchar('\n');
  75. }
  76. else {
  77. int x=a[len-], res=;
  78. while (x) res++, x/=;
  79. printf("%d",a[len-]);
  80. for (int i=len-; i>len--(-res)/; --i) printf("%04d",a[i]);
  81. if ((-res)%) {
  82. int t=(-res)%, tmp=a[len--(-res)/];
  83. FO(i,t,) tmp/=;
  84. if (t==) printf("%d",tmp);
  85. else if (t==) printf("%02d",tmp);
  86. else printf("%03d",tmp);
  87. }
  88. }
  89. }
  90. int cal_len(){
  91. int x=a[len-], res=;
  92. while (x) res++, x/=;
  93. return res+(len-)*;
  94. }
  95. };
  96. BigInt ans;
  97. int main ()
  98. {
  99. int n;
  100. scanf("%d",&n);
  101. ans=BigInt();
  102. while (n>=) ans=ans*BigInt(), n-=;
  103. if (n==) ans=ans*BigInt();
  104. else ans=ans*BigInt(n);
  105. printf("%d\n",ans.cal_len());
  106. ans.output();
  107. return ;
  108. }

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. 成都Uber优步司机奖励政策(3月27日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  2. CC2541工程优化等级的问题

    1. 调试工程的时候发现,优化等级稍微调高一级,就容易出问题,只能用None,其他等级会出现数据丢失的现象.

  3. 问题集 - console.log在IE下不可用

    js中添加如下一段代码即可. if(!window.console){ window.console = {}; } if(!window.console.log){ window.console.l ...

  4. unity3d 计时功能舒爽解决方案

    上次也写了一篇计时功能的博客 今天这篇文章和上次的文章实现思路不一样,结果一样 上篇文章地址:http://www.cnblogs.com/shenggege/p/4251123.html 思路决定一 ...

  5. 开发发布npm module包

    开发发布npm module包 问题 在项目开发过程中,每当进入一个新的业务项目,从零开始搭建一套前端项目结构是一件让人头疼的事情,就要重新复制一个上一个项目的前端框架和组件代码库.其中很多功能的模块 ...

  6. Matlab2018年最新视频教程视频讲义(包含代码)

    2018年Matlab最新视频教程视频讲义(包含代码),适合初学者入门进阶学习,下载地址:百度网盘, https://pan.baidu.com/s/1w4h297ua6ctzfturQ1791g 内 ...

  7. python+selenium 环境配置

    配置环境: python:3.5 selenium:3.3.0 安装方式:python pip install -u selenium windows: 10 firefox:52 因为firefox ...

  8. fiddler不经意的功能

    捕获指定客户端的请求,直接食用 窗口分离,直接食用 Hide this column  隐藏此列Ensure all columns are visible   显示默认所有列Customize co ...

  9. 【转】cocos2dx3.2学习笔记之Director(导演类)

    转载:https://blog.csdn.net/u013435551/article/details/38579747 在Cocos2d-x中,把统筹游戏大局的类抽象为导演类(Director),D ...

  10. Java开发工程师(Web方向) - 04.Spring框架 - 第1章.Spring概述

    第1章.Spring概述 Spring概述 The Spring Framework is a lightweight solution and a potential one-stop-shop f ...