887. 鸡蛋掉落(Hard) / 丢棋子问题

在这里插入图片描述
在这里插入图片描述

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
# 返回最差情况下扔棋子的最小次数
# @param n int整型 楼层数
# @param k int整型 棋子数
# @return int整型
#
import math
class Solution:
    def solve(self , n , k ):
        # write code here
        if n < 1 or k < 1: return 0
        if k == 1: return n # 若只有一个棋子
        if n == 1: return 1 # 若只有一层楼
        
        times = int(math.log(n)/math.log(2)) + 1 # 完全二分需要用的次数(最理想情况)
        if k > times: return times # 若棋子数多于完全二分需要用的次数
        
        dp = [0] * k
        res = 0
        while True:
            res += 1
            prev = 0
            for i in range(k): # 更新一颗棋子可能达到的最高层数
                tmp = dp[i]
                dp[i] += prev + 1
                prev = tmp # prev更新为上一轮dp[i]的最高层数
                
                if dp[i] >= n: # 若当前dp[i]已经达到总楼层数n,则返回扔的最小次数
                    return res

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/home/fujiayu/esp/esp-idf/tools/check_python_dependencies.py:12: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html import pkg_resources Executing action: flash Running ninja in directory /home/fujiayu/esp/hello_world/build Executing "ninja flash"... [1/5] cd /home/fujiayu/esp/hello_world.../esp/hello_world/build/hello_world.bin hello_world.bin binary size 0x31ee0 bytes. Smallest app partition is 0x100000 bytes. 0xce120 bytes (80%) free. [1/1] cd /home/fujiayu/esp/hello_world..._world/build/bootloader/bootloader.bin Bootloader binary size 0x5290 bytes. 0x2d70 bytes (35%) free. [2/3] cd /home/fujiayu/esp/esp-idf/com...nents/esptool_py/run_serial_tool.cmake esptool esp32s3 -p /dev/ttyACM0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 2MB 0x0 bootloader/bootloader.bin 0x10000 hello_world.bin 0x8000 partition_table/partition-table.bin esptool.py v4.6.2 Serial port /dev/ttyACM0 A fatal error occurred: Could not open /dev/ttyACM0, the port doesn't exist CMake Error at run_serial_tool.cmake:66 (message): /home/fujiayu/.espressif/python_env/idf5.2_py3.8_env/bin/python;;/home/fujiayu/esp/esp-idf/components/esptool_py/esptool/esptool.py;--chip;esp32s3 failed. FAILED: CMakeFiles/flash cd /home/fujiayu/esp/esp-idf/components/esptool_py && /usr/bin/cmake -D IDF_PATH=/home/fujiayu/esp/esp-idf -D "SERIAL_TOOL=/home/fujiayu/.espressif/python_env/idf5.2_py3.8_env/bin/python;;/home/fujiayu/esp/esp-idf/components/esptool_py/esptool/esptool.py;--chip;esp32s3" -D "SERIAL_TOOL_ARGS=--before=default_reset;--after=hard_reset;write_flash;@flash_args" -D WORKING_DIRECTORY=/home/fujiayu/esp/hello_world/build -P /home/fujiayu/esp/esp-idf/components/esptool_py/run_serial_tool.cmake ninja: build stopped: subcommand failed. ninja failed with exit code 1, output of the command is in the /home/fujiayu/esp/hello_world/build/log/idf_py_stderr_output_21690 and /home/fujiayu/esp/hello_world/build/log/idf_py_stdout_output_21690
最新发布
07-07

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值