BZOJ 1263 整数划分(数学+高精度)
我们不妨考虑可以划分为实数的情况,设划分为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 整数划分(数学+高精度)的更多相关文章
- BZOJ 1263 整数划分
Description 从文件中读入一个正整数\(n\).要求将\(n\)写成若干个正整数之和,并且使这些正整数的乘积最大. 例如,\(n=13\),则当\(n\)表示为\(4+3+3+3\)(或\( ...
- bzoj1263: [SCOI2006]整数划分(高精度+构造)
第一次写压位高精度只好抄黄学长的 代码最后一段想了好久一看评论区才知道黄学长写错了= =很气 自己最后改对了T^T 这题最优是一直划分3出来直到<=4 #include<iostream& ...
- BZOJ 1263: [SCOI2006]整数划分( 高精度 )
yy一下发现好像越小越好...分解成3*3*3*3……这种形式是最好的...然后就是高精度了 ----------------------------------------------------- ...
- [BZOJ1263][SCOI2006]整数划分(数学+高精度)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1263 分析:数学老师上课讲过啦= =,就是尽可能3越多越好.然后就写个高精度就行了.
- bzoj 3612 [Heoi2014]平衡——整数划分(dp)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3612 因为力矩的缘故,变成了整数划分. 学习到了整数划分.就是那个图一样的套路.https: ...
- bzoj 3612: [Heoi2014]平衡【整数划分dp】
其实就是-n~n中求选k个不同的数,和为0的方案数 学到了新姿势叫整数划分,具体实现是dp 详见:https://blog.csdn.net/Vmurder/article/details/42551 ...
- BZOJ1263: [SCOI2006]整数划分
1263: [SCOI2006]整数划分 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 677 Solved: 332[Submit][Status] ...
- 大概是:整数划分||DP||母函数||递推
整数划分问题 整数划分是一个经典的问题. Input 每组输入是两个整数n和k.(1 <= n <= 50, 1 <= k <= n) Output 对于每组输入,请输出六行. ...
- 【题解】整数划分 [51nod1201] 整数划分 V2 [51nod1259]
[题解]整数划分 [51nod1201] 整数划分 V2 [51nod1259] 传送门:整数划分 \([51nod1201]\) 整数划分 \(V2\) \([51nod1259]\)** [题目描 ...
随机推荐
- 成都Uber优步司机奖励政策(3月27日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- CC2541工程优化等级的问题
1. 调试工程的时候发现,优化等级稍微调高一级,就容易出问题,只能用None,其他等级会出现数据丢失的现象.
- 问题集 - console.log在IE下不可用
js中添加如下一段代码即可. if(!window.console){ window.console = {}; } if(!window.console.log){ window.console.l ...
- unity3d 计时功能舒爽解决方案
上次也写了一篇计时功能的博客 今天这篇文章和上次的文章实现思路不一样,结果一样 上篇文章地址:http://www.cnblogs.com/shenggege/p/4251123.html 思路决定一 ...
- 开发发布npm module包
开发发布npm module包 问题 在项目开发过程中,每当进入一个新的业务项目,从零开始搭建一套前端项目结构是一件让人头疼的事情,就要重新复制一个上一个项目的前端框架和组件代码库.其中很多功能的模块 ...
- Matlab2018年最新视频教程视频讲义(包含代码)
2018年Matlab最新视频教程视频讲义(包含代码),适合初学者入门进阶学习,下载地址:百度网盘, https://pan.baidu.com/s/1w4h297ua6ctzfturQ1791g 内 ...
- python+selenium 环境配置
配置环境: python:3.5 selenium:3.3.0 安装方式:python pip install -u selenium windows: 10 firefox:52 因为firefox ...
- fiddler不经意的功能
捕获指定客户端的请求,直接食用 窗口分离,直接食用 Hide this column 隐藏此列Ensure all columns are visible 显示默认所有列Customize co ...
- 【转】cocos2dx3.2学习笔记之Director(导演类)
转载:https://blog.csdn.net/u013435551/article/details/38579747 在Cocos2d-x中,把统筹游戏大局的类抽象为导演类(Director),D ...
- Java开发工程师(Web方向) - 04.Spring框架 - 第1章.Spring概述
第1章.Spring概述 Spring概述 The Spring Framework is a lightweight solution and a potential one-stop-shop f ...