Hard-题目23:45. Jump Game II

本文介绍了一个算法问题,即如何在给定的非负整数数组中找到从起始位置到达末尾所需的最少跳跃次数。文章提供了详细的算法思路及C语言实现代码。

题目原文:
Given an array of non-negative integers, you are initially positioned at the first index of the array.

Each element in the array represents your maximum jump length at that position.

Your goal is to reach the last index in the minimum number of jumps.

For example:
Given array A = [2,3,1,1,4]

The minimum number of jumps to reach the last index is 2. (Jump 1 step from index 0 to 1, then 3 steps to the last index.)
题目大意:
给出一个正整数数组,你最开始站在数组的开头,每个元素代表你一次跳的最远距离,问你至少需要多少次才能跳到终点?
题目分析:
使用一个变量nextMax记录当前count次跳跃能到达的最远点,并使用count记录已经跳跃的次数。
从头开始遍历数组,设遍历到第i个元素,则当i+num[i]>nextMax时,说明count 次跳跃已经不够用了,则更新nextMax和count。
源码:(language:c)

int jump(int* nums, int numsSize) {
    int count = 0, max = 0,nextMax = 0;
    for (int i = 0 ; i <= max && i < numsSize - 1; i++) {
        nextMax = nextMax> i + nums[i]?nextMax:i+nums[i];
        if (i == max) {
            max = nextMax;
            count++;
        }
    }
    return count;
}

成绩:
7ms,beats 70.37%,8ms,59.26%

内容概要:本文介绍了一个基于Matlab的综合能源系统优化调度仿真资源,重点实现了含光热电站、有机朗肯循环(ORC)和电含光热电站、有机有机朗肯循环、P2G的综合能源优化调度(Matlab代码实现)转气(P2G)技术的冷、热、电多能互补系统的优化调度模型。该模型充分考虑多种能源形式的协同转换与利用,通过Matlab代码构建系统架构、设定约束条件并求解优化目标,旨在提升综合能源系统的运行效率与经济性,同时兼顾灵活性供需不确定性下的储能优化配置问题。文中还提到了相关仿真技术支持,如YALMIP工具包的应用,适用于复杂能源系统的建模与求解。; 适合人群:具备一定Matlab编程基础和能源系统背景知识的科研人员、研究生及工程技术人员,尤其适合从事综合能源系统、可再生能源利用、电力系统优化等方向的研究者。; 使用场景及目标:①研究含光热、ORC和P2G的多能系统协调调度机制;②开展考虑不确定性的储能优化配置与经济调度仿真;③学习Matlab在能源系统优化中的建模与求解方法,复现高水平论文(如EI期刊)中的算法案例。; 阅读建议:建议读者结合文档提供的网盘资源,下载完整代码和案例文件,按照目录顺序逐步学习,重点关注模型构建逻辑、约束设置与求解器调用方式,并通过修改参数进行仿真实验,加深对综合能源系统优化调度的理解。
行 13462: 10-30 14:23:40.963614 2405 2405 E perfetto: tats_data_source.cc:268 Failed to open /sys/class/devfreq/ (errno: 13, Permission denied) 行 16165: 10-30 14:23:41.963445 4455 4533 W libc : Access denied finding property "vendor.gsm.serial" 行 16222: 10-30 14:23:42.015218 4455 4533 W libc : Access denied finding property "vendor.gsm.serial" 行 16337: 10-30 14:23:42.074259 4455 10052 W libc : Access denied finding property "vendor.gsm.serial" 行 19065: 10-30 14:23:42.935439 20217 20217 W libc : Access denied finding property "persist.vendor.sys.activitylog" 行 20124: 10-30 14:23:43.328923 20217 20304 E SchedAssist: open sharedFd failed with error=Permission denied 行 20125: 10-30 14:23:43.329035 20217 20304 E SchedAssist: open sharedFd failed with error=Permission denied 行 20127: 10-30 14:23:43.329062 20217 20304 E SchedAssist: open sharedFd failed with error=Permission denied 行 20128: 10-30 14:23:43.329072 20217 20304 E SchedAssist: open sharedFd failed with error=Permission denied 行 20497: 10-30 14:23:43.480338 20328 20328 W libc : Access denied finding property "persist.vendor.sys.activitylog" 行 20782: 10-30 14:23:43.649296 20217 20271 W libc : Access denied finding property "ro.serialno" 行 20786: 10-30 14:23:43.649914 20217 20271 W libc : Access denied finding property "ro.serialno" 行 20835: 10-30 14:23:43.670603 20380 20380 W libc : Access denied finding property "ro.serialno" 行 20854: 10-30 14:23:43.677196 20217 20217 W libc : Access denied finding property "ro.debuggable" 行 21420: 10-30 14:23:43.841572 20217 20295 W libc : Access denied finding property "vendor.boot.vbmeta.device_state" 行 21421: 10-30 14:23:43.841618 20217 20295 W libc : Access denied finding property "ro.vendor.warranty_bit" 行 21423: 10-30 14:23:43.841638 20217 20295 W libc : Access denied finding property "ro.vendor.boot.warranty_bit" 行 21437: 10-30 14:23:43.844405 20217 20217 W libc : Access denied finding property "ro.debuggable" 行 21439: 10-30 14:23:43.845227 20217 20217 W libc : Access denied finding property "ro.debuggable" 行 21458: 10-30 14:23:43.848830 20217 20217 W libc : Access denied finding property "ro.debuggable" 行 21567: 10-30 14:23:43.884732 20217 20295 W libc : Access denied finding property "ro.secure" 行 21568: 10-30 14:23:43.884772 20217 20295 W libc : Access denied finding property "ro.debuggable" 行 21619: 10-30 14:23:43.920794 4696 6233 W TelephonyPermissions: reportAccessDeniedToReadIdentifiers:sg.bigo.live:getSubscriberIdForSubscriber:-1 行 22122: 10-30 14:23:44.119837 20328 20464 W libc : Access denied finding property "ro.serialno" 行 22123: 10-30 14:23:44.120671 20328 20464 W libc : Access denied finding property "ro.serialno" 行 22177: 10-30 14:23:44.179626 20514 20514 W libc : Access denied finding property "ro.serialno" 行 22806: 10-30 14:23:44.509862 20328 20476 W libc : Access denied finding property "vendor.boot.vbmeta.device_state" 行 22807: 10-30 14:23:44.509963 20328 20476 W libc : Access denied finding property "ro.vendor.warranty_bit" 行 22808: 10-30 14:23:44.509984 20328 20476 W libc : Access denied finding property "ro.vendor.boot.warranty_bit" 行 22856: 10-30 14:23:44.554277 20328 20476 W libc : Access denied finding property "ro.secure" 行 22857: 10-30 14:23:44.554354 20328 20476 W libc : Access denied finding property "ro.debuggable" 行 22884: 10-30 14:23:44.586780 4696 6233 W TelephonyPermissions: reportAccessDeniedToReadIdentifiers:sg.bigo.live:getSubscriberIdForSubscriber:-1 行 23536: 10-30 14:23:45.244199 20217 20217 W libc : Access denied finding property "ro.debuggable" 行 23809: 10-30 14:23:45.582676 20217 20217 W libc : Access denied finding property "ro.debuggable" 行 26105: 10-30 14:23:46.929048 2496 14600 I AttributionAndPermissionUtils: checkPermission (forDataDelivery 0 startDataDelivery 0): Permission hard denied for client attribution [uid 10370, pid 20217, packageName "<unknown>"] 行 26107: 10-30 14:23:46.930287 20217 20411 W libc : Access denied finding property "vendor.camera.aux.packagelist" 行 26111: 10-30 14:23:46.931919 20217 20411 W libc : Access denied finding property "vendor.camera.aux.packagelist" 行 26114: 10-30 14:23:46.933312 20217 20411 W libc : Access denied finding property "vendor.camera.aux.packagelist" 行 26119: 10-30 14:23:46.938428 20217 20411 W libc : Access denied finding property "vendor.camera.aux.packagelist" 行 26121: 10-30 14:23:46.938976 20217 20411 W libc : Access denied finding property "vendor.camera.aux.packagelist" 行 26334: 10-30 14:23:47.024803 2010 7490 D AudioPolicyManagerExtImpl: checkUllCompatible() denied raw flag on session 241 for performance noise 行 26341: 10-30 14:23:47.025483 2010 7490 D AudioFlinger: AF createTrack_l, skip effectchain::checkOutputFlagCompatibility to avoid fast flag to be denied by global effects, pid 20217, session -1 行 26374: 10-30 14:23:47.029000 2010 2010 W AudioRtBoostThr: type=1400 audit(0.0:1008): avc: denied { getsched } for scontext=u:r:audioserver:s0 tcontext=u:r:untrusted_app:s0:c114,c257,c512,c768 tclass=process permissive=0 行 26412: 10-30 14:23:47.037000 2010 2010 W AudioRtBoostThr: type=1400 audit(0.0:1009): avc: denied { getsched } for scontext=u:r:audioserver:s0 tcontext=u:r:untrusted_app:s0:c114,c257,c512,c768 tclass=process permissive=0 行 26414: 10-30 14:23:47.045432 20217 20411 W libc : Access denied finding property "ro.hardware.chipname" 行 26449: 10-30 14:23:47.057000 2010 2010 W AudioRtBoostThr: type=1400 audit(0.0:1010): avc: denied { getsched } for scontext=u:r:audioserver:s0 tcontext=u:r:untrusted_app:s0:c114,c257,c512,c768 tclass=process permissive=0 行 26588: 10-30 14:23:47.101000 2010 2010 W AudioRtBoostThr: type=1400 audit(0.0:1011): avc: denied { getsched } for scontext=u:r:audioserver:s0 tcontext=u:r:untrusted_app:s0:c114,c257,c512,c768 tclass=process permissive=0 行 29179: 10-30 14:23:48.226797 2496 14600 I AttributionAndPermissionUtils: checkPermission (forDataDelivery 0 startDataDelivery 0): Permission hard denied for client attribution [uid 10370, pid 20217, packageName "<unknown>"]
11-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值