{"id":518,"date":"2024-05-30T09:00:00","date_gmt":"2024-05-30T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=518"},"modified":"2024-05-07T17:06:28","modified_gmt":"2024-05-07T09:06:28","slug":"zerojudge-a540","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-a540\/","title":{"rendered":"ZeroJudge A540: The jackpot"},"content":{"rendered":"\n\n\n<h4 class=\"wp-block-heading\">\u540c\u984c\uff1aUVa 10684 &#8211; The jackpot<\/h4>\n\n\n\n<p class=\"\">\u6709\u4e00\u500b\u4eba\u60f3\u8981\u5feb\u901f\u7684\u81f4\u5bcc\u800c\u4e14\u4e0d\u7528\u592a\u8f9b\u82e6\u5de5\u4f5c\uff0c\u4ed6\u6c7a\u5b9a\u8981\u5728\u4ee5\u8ced\u5834\u4f5c\u70ba\u751f\u6daf\u8077\u5834\u3002\u6240\u4ee5\u4ed6\u958b\u59cb\u7814\u7a76\u5225\u7684\u8ced\u5ba2\u8f38\u8d0f\u7684\u60c5\u6cc1\uff0c\u9019\u6a23\u4ed6\u624d\u80fd\u5236\u8a02\u4e00\u500b\u8d0f\u7684\u7b56\u7565\u3002\u7531\u65bc\u4ed6\u4e0d\u61c2\u96fb\u8166\uff0c\u6240\u4ee5\u4ed6\u96c7\u7528\u4f60\u5beb\u4e00\u500b\u7a0b\u5f0f\u4f86\u5e6b\u52a9\u4ed6\u3002<\/p>\n\n\n\n<p class=\"\">\u4f60\u9996\u5148\u7684\u4efb\u52d9\u662f\u5beb\u4e00\u500b\u7a0b\u5f0f\u5728\u4e00\u9023\u4e32\u7684\u8ced\u5c40\u4e2d\u8fa8\u8b58\u51fa\u9023\u7e8c\u7684\u8ced\u5c40\u6700\u5927\u53ef\u80fd\u8d0f\u7684\u9322\u3002\u6bcf\u5834\u8ced\u5c40\u4ee5\u4e00\u500b\u6574\u6578\u4f86\u8868\u793a\u8d0f\u6216\u8f38\u7684\u91d1\u984d\u3002\u6b63\u6578\u4ee3\u8868\u8d0f\uff0c\u8ca0\u6578\u4ee3\u8868\u8f38\u3002<\/p>\n\n\n\n<p class=\"\">\u4f8b\u5982\uff1a\u6709 6 \u5c40\u8ced\u5c40\u91d1\u984d\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p class=\"\">-99 10 -9 10 -5 4<\/p>\n\n\n\n<p class=\"\">\u9023\u7e8c\u7684\u8ced\u5c40\u6700\u5927\u53ef\u80fd\u8d0f\u7684\u9322\u70ba 11\uff0c\u51fa\u73fe\u5728\u7b2c 2\u30013\u30014 \u9019\u9023\u7e8c\u4e09\u5c40\u4e2d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td><strong>EOF<\/strong> \u8f38\u5165\uff0c\u6bcf\u7d44\u6e2c\u8a66\u8cc7\u6599\u7684\u7b2c\u4e00\u5217\u6709\u4e00\u500b\u6b63\u6574\u6578 N &lt;=  10000\uff0c\u4ee3\u8868\u6578\u5217\u7684\u9577\u5ea6\u3002\u63a5\u4e0b\u4f86\u6709 N \u500b\u6574\u6578  (\u7d55\u5c0d\u503c\u5c0f\u65bc 1000\uff09\uff0c\u4ee3\u8868\u9019 N \u5c40\u8ced\u5c40\u8f38\u8d0f\u7684\u91d1\u984d\u3002<br>\u7576 N = 0 \u4ee3\u8868\u8f38\u5165\u7d50\u675f\u3002\u8acb\u53c3\u8003 Sample Input\u3002<\/td><td>\u5c0d\u6bcf\u7d44\u6e2c\u8a66\u8cc7\u6599\u8f38\u51fa\u4e00\u5217\uff0c\u5728\u9019 N \u5c40\u8ced\u5c40\u4e2d\uff0c\u9023\u7e8c\u7684\u8ced\u5c40\u6700\u5927\u53ef\u80fd\u8d0f\u7684\u9322\u662f\u591a\u5c11\u3002<br>\u5982\u679c\u8f38\u5165\u7684\u8cc7\u6599\u4e0d\u53ef\u80fd\u8d0f\u9322\uff0c\u5247\u8f38\u51fa\u300cLosing streak.\u300d\u3002<br>\u8f38\u51fa\u683c\u5f0f\u8acb\u53c3\u8003Sample Output\u3002<\/td><\/tr><tr><td>6<br>-99 10 -9 10 -5 4<br>3<br>-999 100 -9<br>5<br>12 -4 -10 4 9<br>3<br>-2 -1 -2<br>0<\/td><td>The maximum winning streak is 11.<br>The maximum winning streak is 100.<br>The maximum winning streak is 13.<br>Losing streak.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\">\u4f7f\u7528\u9663\u5217\u5148\u5c07\u8cc7\u6599\u6536\u8d77\u4f86\uff0c\u518d\u4f86\u8dd1\u4e00\u500b For \u8ff4\u5708\uff0c\u9019\u500b\u662f\u6bcf\u6b21\u8a08\u7b97\u7684\u300c\u8d77\u9ede\u300d\uff0c\u8981\u5f9e i = 0 \u8dd1\u5230 i = N-1\u3002\u88e1\u9762\u9084\u9700\u8981\u4e00\u500b For \u8ff4\u5708\uff0c\u8981\u5f9e j = i \u8dd1\u5230 j = N-1\uff0c\u4ee3\u8868\u8981\u5f9e\u8d77\u9ede i \u958b\u59cb\u52a0\u5230\u6700\u5f8c\u7684\u7d42\u9ede\u3002<\/p>\n\n\n\n<p class=\"\">\u53ef\u4ee5\u9810\u8a2d\u4e00\u500b ans \u8b8a\u6578\u70ba -9999\uff0c\u6bcf\u4e00\u6b21\u6709\u76f8\u52a0\u52d5\u4f5c\u6642\u5c31\u548c ans \u6bd4\u5927\u5c0f\uff0c\u5982\u679c\u76ee\u524d\u76f8\u52a0\u7684\u6578\u5b57\u6bd4 ans \u5927\u5c31\u5c07\u5176\u8a2d\u70ba ans\u3002<\/p>\n\n\n\n<p class=\"\">\u6700\u5f8c\u5224\u65b7 ans \u662f\u5426\u6709 > 0\uff0c\u5982\u679c\u6709\u5c31\u8f38\u51fa ans\uff0c\u6c92\u6709\u5c31\u8f38\u51fa\u300cLosing streak.\u300d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a540\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge A540: The jackpot<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right nfd-delay-50\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;vector&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N;\n    while (cin &gt;&gt; N && N != 0)\n    {\n        vector&lt;int&gt;num;\n        int ans = -9999;\n        for (int i = 0; i&lt;N; i++)\n        {\n            int tmp;\n            cin &gt;&gt; tmp;\n            num.push_back(tmp);\n        }\n        for (int i = 0; i&lt;N; i++)\n        {\n            int sum = 0;\n            for (int j = i; j&lt;N; j++)\n            {\n                sum += num[j];\n                ans = max(ans, sum);\n            }\n        }\n        if (ans &gt; 0)\n        {\n            cout &lt;&lt; &quot;The maximum winning streak is &quot; &lt;&lt; ans &lt;&lt; &quot;.\\n&quot;;\n            continue;\n        }\n        cout &lt;&lt; &quot;Losing streak.\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge A540\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 10684 &#8211; The jackpot \u6709\u4e00\u500b\u4eba\u60f3\u8981\u5feb\u901f\u7684\u81f4\u5bcc\u800c\u4e14\u4e0d\u7528\u592a\u8f9b\u82e6\u5de5\u4f5c\uff0c\u4ed6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[18],"tags":[20,8,13,9],"class_list":["post-518","post","type-post","status-publish","format-standard","hentry","category-uva","tag-20","tag-8","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/comments?post=518"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/518\/revisions"}],"predecessor-version":[{"id":519,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/518\/revisions\/519"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}