{"id":84,"date":"2022-12-14T13:29:54","date_gmt":"2022-12-14T05:29:54","guid":{"rendered":"https:\/\/www.vcoco.top\/?p=84"},"modified":"2022-12-14T13:29:54","modified_gmt":"2022-12-14T05:29:54","slug":"pat-%e6%9c%80%e5%a4%a7%e5%ad%90%e5%ba%8f%e5%92%8c","status":"publish","type":"post","link":"https:\/\/www.vcoco.top\/index.php\/2022\/12\/14\/pat-%e6%9c%80%e5%a4%a7%e5%ad%90%e5%ba%8f%e5%92%8c\/","title":{"rendered":"PAT \u6700\u5927\u5b50\u5e8f\u548c"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">\u52a8\u6001\u67e5\u627e<\/h3>\n\n\n\n<p><code>e<\/code>\uff1a\u5b50\u6bb5\u7ec8\u70b9<br><code>b<\/code>\uff1a\u5b50\u6bb5\u8d77\u70b9<br><code>btmp<\/code>\uff1a\u5b50\u6bb5\u4e34\u65f6\u8d77\u70b9<br><code>sum<\/code>\uff1a\u7528\u6765\u76f8\u52a0\u627e\u6700\u5927\u503c<br><code>res<\/code>\uff1a\u6700\u5927\u503c<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u7b97\u6cd5\u601d\u60f3<\/h4>\n\n\n\n<p>\u6bcf\u4e00\u8f6e\u7528<code>sum<\/code>\u7d2f\u52a0\uff0c\u5224\u65ad<code>sum<\/code>\u4e0e\u662f\u5426\u6bd4\u4e4b\u524d\u786e\u5b9a\u7684<code>res<\/code>\u66f4\u5927\uff0c\u5982\u679c\u662f\uff0c\u5219\u66f4\u65b0<code>sum<\/code>\uff0c\u5e76\u4e14\u66f4\u65b0\u8d77\u70b9\u548c\u7ec8\u70b9\uff0c\u5982\u679c<code>sum&lt;0<\/code>\u4e86\uff0c\u8a00\u5916\u4e4b\u610f\u5c31\u662f\u524d\u9762\u7684\u5b50\u6bb5\u90fd\u53ef\u4ee5\u4e0d\u8981\u4e86\uff0c\u4ece<code>i+1<\/code>\u4e0b\u6807\u91cd\u65b0\u5f00\u59cb\uff08\u52a0\u4e0a\u524d\u9762\u7684\u8d1f\u6570\u8fd8\u4e0d\u5982\u4e0d\u52a0\uff09\uff0c\u8fd9\u65f6\u7528<code>btmp<\/code>\u786e\u5b9a\u4e34\u65f6\u8d77\u70b9\u4e3a<code>i+1<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\n\nusing namespace std;\n\nconst int N = 10010, INF = 0x3f3f3f3f;\n\nint n, a&#91;N];\n\nint main()\n{\n    cin &gt;&gt; n;\n    for (int i = 0; i &lt; n; i ++) cin &gt;&gt; a&#91;i];\n\n    int res = -INF, sum = 0, b = 0, e = 0, btmp = 0;\n    for (int i = 0; i &lt; n; i ++)\n    {\n        sum += a&#91;i];\n        if (sum &gt; res) e = i, b = btmp, res = sum;\n        if (sum &lt; 0) sum = 0, btmp = i + 1;\n    }\n\n    if (res &lt; 0) res = 0, b = 0, e = n - 1;\n    cout &lt;&lt; res &lt;&lt;' '&lt;&lt; a&#91;b] &lt;&lt;' '&lt;&lt; a&#91;e] &lt;&lt; endl;\n\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u9644\u4e0a\u6b63\u89c4\u52a8\u6001\u89c4\u5212\u7684\u7b97\u6cd5<\/h3>\n\n\n\n<p><strong>\u72b6\u6001\u8f6c\u79fb\uff1a<\/strong><code>f[i]=max(f[i-1]+a[i],a[i]);<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\n\nusing namespace std;\n\nconst int N = 1000010, INF = 0x3f3f3f3f;\n\nint a&#91;N], n;\nint f&#91;N];   \/\/\u4ee5i\u7ed3\u5c3e\u7684\u6700\u5927\u5b50\u5e8f\u5217\n\nint main()\n{\n    cin &gt;&gt; n;\n    for (int i = 1; i &lt;= n; i++) scanf(\"%d\", &amp;a&#91;i]);\n\n    int res = -INF, b = 1, e = 1, btmp = 1;\n    for (int i = 1; i &lt;= n; i ++)\n    {\n        f&#91;i] = max(f&#91;i - 1] + a&#91;i], a&#91;i]);\n        if (f&#91;i - 1] &lt; 0) btmp = i;\n        if (res &lt; f&#91;i]) res = f&#91;i], e = i, b = btmp;\n    }\n\n    if (res &lt; 0) res = 0, b = 1, e = n;\n    cout &lt;&lt; res &lt;&lt;' '&lt;&lt; a&#91;b] &lt;&lt;' '&lt;&lt; a&#91;e] &lt;&lt; endl;\n\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u52a8\u6001\u67e5\u627e e\uff1a\u5b50\u6bb5\u7ec8\u70b9b\uff1a\u5b50\u6bb5\u8d77\u70b9btmp\uff1a\u5b50\u6bb5\u4e34\u65f6\u8d77\u70b9sum\uff1a\u7528\u6765\u76f8\u52a0\u627e\u6700\u5927\u503cres\uff1a\u6700\u5927\u503c \u7b97\u6cd5\u601d\u60f3 \u6bcf\u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[59,45],"class_list":["post-84","post","type-post","status-publish","format-standard","hentry","category-mess","tag-pat","tag-45"],"_links":{"self":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts\/84","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":1,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"predecessor-version":[{"id":85,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/posts\/84\/revisions\/85"}],"wp:attachment":[{"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vcoco.top\/index.php\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}