当前位置:网站首页>《剑指Offer》剪绳子
《剑指Offer》剪绳子
2022-07-27 14:15:00 【傻子是小傲娇】
题目描述
给你一根长度为n的绳子,请把绳子剪成m段(m、n都是整数,n>1并且m>1),每段绳子的长度记为k[0],k[1],...,k[m]。请问k[0]xk[1]x...xk[m]可能的最大乘积是多少?例如,当绳子的长度是8时,我们把它剪成长度分别为2、3、3的三段,此时得到的最大乘积是18
乘法计算,除了一以外,越多的数相乘结果越大
从2开始考虑,如果用2分段,存在奇数最后会留下一个2,1,这时
应该换为3,因此2,3分段
2*2*2<3*3,应该让3尽可能的多一些
用数%3,余数为2则存在一个2,为1则存在两个2class Solution { public: int cutRope(int target) { if(target<=3)return target-1; int res=1;//%3=0 if(target%3==1){ res=4; target-=4; }else if(target%3==2){ res=2; target-=2; } while(target){ res*=3; target-=3; } return res; } };
边栏推荐
- Stock trading 4
- The database uses PSQL and JDBC to connect remotely and disconnect automatically from time to time
- internship:其他配置类的编写
- [Yunxiang book club issue 13] multimedia processing tool ffmpeg tool set
- 网络设备硬核技术内幕 路由器篇 6 汤普金森漫游网络世界(中)
- web上构建3d效果 基于three.js的实例
- The mobile terminal uses the list component of vantui. When multiple tab items are switched back and forth, the list is loaded many times, resulting in the failure of normal display of data
- JUC(JMM、Volatile)
- 南山区民政局关于开展2022年度南山区社会组织等级评估工作的通知
- [Yunxiang book club issue 13] packaging format of video files
猜你喜欢

基于stm32的数字示波器设计方案
![[ManageEngine] what is Siem](/img/a6/0fbe60df6bef337a91a10fe046aa8a.jpg)
[ManageEngine] what is Siem
![[work] about technical architecture](/img/24/f3402c04157ce9a8846580f017f472.png)
[work] about technical architecture
MOS管防止电源反接的原理

Kubernetes CNI 分类/运行机制

视觉系统设计实例(halcon-winform)-9.文字显示

Idea makes jar packages and introduces jar packages

对话框管理器第三章:创建控件

Lecture 4: Longest ascending substring

Skywalking distributed system application performance monitoring tool - medium
随机推荐
两阶段提交与三阶段提交
LeetCode 面试题 17.21. 直方图的水量 双指针,单调栈/hard
国信证券手机开户安全吗 中山证券靠谱吗
Data warehouse project is never a technical project
If we were the developer responsible for repairing the collapse of station B that night
【云享读书会第13期】多媒体处理工具 FFmpeg 工具集
网络设备硬核技术内幕 路由器篇 9 CISCO ASR9900拆解 (二)
网络设备硬核技术内幕 路由器篇 20 DPDK (五)
网络设备硬核技术内幕 路由器篇 5 汤普金森漫游网络世界(上)
电子制造行业的数字化转型突破点在哪?精益制造是关键
MOS管防止电源反接的原理
通过VN1630/VN7640的I/O功能来确认电源设置电压的时间精确度
[work] about technical architecture
LeetCode 341.扁平化嵌套列表迭代器 dfs,栈/ Medium
关于 CMS 垃圾回收器,你真的懂了吗?
Hdu3117 Fibonacci numbers [mathematics]
谷歌团队推出新Transformer,优化全景分割方案|CVPR 2022
NEFU119 组合素数【算术基本定理】
HDU3117 Fibonacci Numbers【数学】
Internship: compilation of other configuration classes