{"id":3128,"date":"2022-02-06T14:36:26","date_gmt":"2022-02-06T06:36:26","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=3128"},"modified":"2024-05-05T14:19:26","modified_gmt":"2024-05-05T06:19:26","slug":"%e5%ad%90%e6%95%b0%e7%bb%84%e6%9c%80%e5%a4%a7%e5%b9%b3%e5%9d%87%e6%95%b0","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=3128","title":{"rendered":"\u5b50\u6570\u7ec4\u6700\u5927\u5e73\u5747\u6570"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title ez-toc-toggle\" style=\"cursor:pointer\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.iyatt.com\/?p=3128\/#%E9%A2%98%E7%9B%AE\" >\u9898\u76ee<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.iyatt.com\/?p=3128\/#%E6%B5%8B%E8%AF%95%E6%9D%A1%E4%BB%B6\" >\u6d4b\u8bd5\u6761\u4ef6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.iyatt.com\/?p=3128\/#%E5%88%86%E6%9E%90\" >\u5206\u6790<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.iyatt.com\/?p=3128\/#%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0\" >\u4ee3\u7801\u5b9e\u73b0<\/a><\/li><\/ul><\/nav><\/div>\n\n<h2 class=\"wp-block-heading\" id=\"\u9898\u76ee\"><span class=\"ez-toc-section\" id=\"%E9%A2%98%E7%9B%AE\"><\/span>\u9898\u76ee<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u627e\u51fa\u5e73\u5747\u6570\u6700\u5927\u4e14\u957f\u5ea6\u4e3a k \u7684\u5b50\u6570\u7ec4\uff0c\u5e76\u5c06\u6700\u5927\u5e73\u5747\u503c\u4f5c\u4e3a\u8fd4\u56de\u7ed3\u679c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u6d4b\u8bd5\u6761\u4ef6\"><span class=\"ez-toc-section\" id=\"%E6%B5%8B%E8%AF%95%E6%9D%A1%E4%BB%B6\"><\/span>\u6d4b\u8bd5\u6761\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>gcc 9.4.0 \u2013 64\u4f4d<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-no-pie -std=c17 -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Werror=format-security -Wextra -pedantic -Wimplicit-fallthrough -Wsequence-point -Wswitch-unreachable -Wswitch-enum -Wstringop-truncation -Wbool-compare -Wtautological-compare -Wfloat-equal -Wshadow=global -Wpointer-arith -Wpointer-compare -Wcast-align -Wcast-qual -Wwrite-strings -Wdangling-else -Wlogical-op -Wconversion -g -O0 -lm<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5206\u6790\"><span class=\"ez-toc-section\" id=\"%E5%88%86%E6%9E%90\"><\/span>\u5206\u6790<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u8fd9\u4e2a\u9898\u76ee\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u6ed1\u52a8\u7a97\u53e3\u601d\u60f3\u6765\u89e3\u7b54\uff0c\u9996\u5148\u5148\u8ba1\u7b97\u51fa\u524d k \u4e2a\u6570\u7ec4\u4e4b\u548c\u5e76\u8bb0\u5f55\uff0c\u7136\u540e\u4e0b\u4e00\u8f6e\u5728\u524d\u4e00\u8f6e\u4e4b\u548c\u7684\u57fa\u7840\u4e0a\u51cf\u53bb\u7b2c 1 \u4e2a\u6570\u7ec4\u503c\uff0c\u5e76\u52a0\u4e0a\u7b2c k+1 \u4e2a\u6570\u7ec4\u503c\uff0c\u5e76\u6bd4\u8f83\u4e0e\u4e0a\u4e00\u8f6e k \u4e2a\u4e4b\u548c\uff0c\u5982\u679c\u66f4\u5927\u5c31\u4fdd\u5b58\u5e76\u66ff\u6362\u539f\u6765\u8bb0\u5f55\u7684\u6700\u5927\u503c\uff0c\u53c8\u662f\u4e00\u8f6e\uff0c\u5728 k \u4e2a\u6570\u4e4b\u548c\u57fa\u7840\u4e0a\u51cf\u53bb\u7b2c 2 \u4e2a\u6570\u7ec4\u503c\uff0c\u518d\u52a0\u4e0a\u7b2c k+2 \u4e2a\u6570\u7ec4\u503c\uff0c\u518d\u6bd4\u8f83\u548c\u4e0a\u4e00\u8f6e\u7684\u6700\u5927\u503c&#8230;&#8230; \u4e5f\u5c31\u662f\u6bcf\u4e00\u8f6e\u51cf\u53bb\u4e0a\u4e00\u8f6e\u7684 k \u4e2a\u6570\u4e4b\u548c\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5e76\u52a0\u4e0a\u4e0b\u4e00\u4e2a\uff0c\u4e5f\u5c31\u5b9e\u73b0\u4e86\u4f9d\u6b21\u8ba1\u7b97\u8fde\u7eed\u7684\u56db\u4e2a\u6700\u5927\u503c\u4e4b\u548c\uff0c\u8fd4\u56de\u503c\u7b97\u5e73\u5747\u503c\u5373\u53ef\uff0c\u6ce8\u610f\u4f20\u5165\u7684\u6570\u7ec4\u5143\u7d20\u4e3a\u6574\u6570\uff0c\u8ba1\u7b97\u5e73\u5747\u6570\u5e94\u8be5\u8f6c\u4e3a\u6d6e\u70b9\u6570\u8fdb\u884c\u8ba1\u7b97\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u6309\u7167\u66b4\u529b\u679a\u4e3e\u7684\u601d\u60f3\uff0c\u7b2c\u4e00\u8f6e\u8ba1\u7b97\u7b2c 1\u30012&#8230;k \u4e2a\u6570\u7ec4\u503c\u76f8\u52a0\uff0c\u7b2c 2 \u8f6e\u8ba1\u7b97\u7b2c 2\u30013&#8230;k+1 \u4e2a\u6570\u7ec4\u76f8\u52a0\uff0c\u7b2c 3 \u8f6e\u8ba1\u7b97 3\u30014&#8230;k+2 \u4e2a\u6570\u7ec4\u76f8\u52a0&#8230;&#8230;\u3002\u6bcf\u4e00\u8f6e\u90fd\u662f k \u4e2a\u6570\u76f8\u52a0\uff0c\u76f8\u6bd4\u4e0e\u6ed1\u52a8\u7a97\u53e3\u6bcf\u4e00\u8f6e\u53ea\u51cf\u53bb\u7b2c\u4e00\u4e2a\u5e76\u52a0\u4e0a\u4e0b\u4e00\u4e2a\u800c\u8a00\u8ba1\u7b97\u91cf\u66f4\u5927\uff0c\u6548\u7387\u66f4\u4f4e\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4ee3\u7801\u5b9e\u73b0\"><span class=\"ez-toc-section\" id=\"%E4%BB%A3%E7%A0%81%E5%AE%9E%E7%8E%B0\"><\/span>\u4ee3\u7801\u5b9e\u73b0<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">float solution(int *nums, size_t size, size_t k)\n{\n    int sum = 0;\n    for (size_t i = 0; i &lt; k; ++i)  \/\/ \u524d k \u4e2a\u6570\u4e4b\u548c\n    {\n        sum += nums[i];\n    }\n    int max = 0;\n    for (size_t i = k; i &lt; size; ++i) \/\/ \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\u5f80\u540e\u6ed1\u52a8\n    {\n        if (sum > max)\n        {\n            max = sum;\n        }\n        sum = sum - nums[i-k] + nums[i];  \/\/ \u51cf\u53bb\u4e0a\u4e00\u8f6e\u7684\u7b2c\u4e00\u4e2a\uff0c\u52a0\u4e0a\u540e\u4e00\u4f4d\n    }\n    return (float)max \/ (float)k;\n}<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"712\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/02\/2022-02-06-14-36-03-\u7684\u5c4f\u5e55\u622a\u56fe-1024x712.png\" alt=\"\" class=\"wp-image-3132 lazyload\" data-srcset=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/02\/2022-02-06-14-36-03-\u7684\u5c4f\u5e55\u622a\u56fe-1024x712.png 1024w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/02\/2022-02-06-14-36-03-\u7684\u5c4f\u5e55\u622a\u56fe-300x209.png 300w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/02\/2022-02-06-14-36-03-\u7684\u5c4f\u5e55\u622a\u56fe-768x534.png 768w, https:\/\/blog.iyatt.com\/wp-content\/uploads\/2022\/02\/2022-02-06-14-36-03-\u7684\u5c4f\u5e55\u622a\u56fe.png 1275w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/712;\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee \u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4\uff0c\u627e\u51fa\u5e73\u5747\u6570\u6700\u5927\u4e14\u957f\u5ea6\u4e3a k \u7684\u5b50\u6570\u7ec4\uff0c\u5e76\u5c06\u6700\u5927\u5e73\u5747\u503c\u4f5c\u4e3a\u8fd4\u56de\u7ed3\u679c\u3002 \u6d4b\u8bd5\u6761\u4ef6 gcc  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-3128","post","type-post","status-publish","format-standard","hentry","category-all"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/3128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3128"}],"version-history":[{"count":0,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/3128\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}