当前位置:网站首页>《剑指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; } };
边栏推荐
- Skywalking distributed system application performance monitoring tool - medium
- USB接口电磁兼容(EMC)解决方案
- Passive income: return to the original and safe two ways to earn
- 谷歌团队推出新Transformer,优化全景分割方案|CVPR 2022
- 网络设备硬核技术内幕 路由器篇 (10) CISCO ASR9900拆解 (四)
- 工具 - markdown编辑器常用方法
- LeetCode 341.扁平化嵌套列表迭代器 dfs,栈/ Medium
- USB2.0接口的EMC设计方案
- LeetCode 74. 搜索二维矩阵 二分/medium
- See "sense of security" in uncertainty Volvo asked in 2022
猜你喜欢

LeetCode 面试题 17.21. 直方图的水量 双指针,单调栈/hard

ADB command (install APK package format: ADB install APK address package name on the computer)

移动端使用vantUI的list组件,多个tab项来回切换时,列表加载多次导致数据无法正常展示

SkyWalking分布式系统应用程序性能监控工具-中

仅做两项修改,苹果就让StyleGANv2获得了3D生成能力

LeetCode 74. 搜索二维矩阵 二分/medium

如果我们是那晚负责修复 B 站崩了的开发人员

USB2.0接口的EMC设计方案

Graphic SQL of giant image

泛型
随机推荐
Code coverage statistical artifact -jacobo tool practice
See "sense of security" in uncertainty Volvo asked in 2022
关于 CMS 垃圾回收器,你真的懂了吗?
How to help enterprises optimize office management
Disk troubleshooting of kubernetes node
Kotlin的基础用法
OBS 进阶之 DXGI 采集屏幕流程,并如何修改为自己的光标
cap理论和base理论
IJCAI 2022杰出论文公布,大陆作者中稿298篇拿下两项第一
[Yunxiang book club issue 13] packaging format of video files
Graphic SQL of giant image
The database uses PSQL and JDBC to connect remotely and disconnect automatically from time to time
Is there a regular and safe account opening platform for gold speculation
网络设备硬核技术内幕 路由器篇 13 从鹿由器到路由器(上)
关于印发《深圳市工业和信息化局绿色制造试点示范管理暂行办法》的通知
[medical industry] DICOM converter tools
电子制造行业的数字化转型突破点在哪?精益制造是关键
Unity3D学习笔记10——纹理数组
Dynamic programming - stock trading 5
SkyWalking分布式系统应用程序性能监控工具-中