{"id":974,"date":"2024-07-30T09:00:00","date_gmt":"2024-07-30T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=974"},"modified":"2024-06-25T18:58:34","modified_gmt":"2024-06-25T10:58:34","slug":"zerojudge-n686","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-n686\/","title":{"rendered":"ZeroJudge N686: \u8a0a\u865f\u50b3\u905e"},"content":{"rendered":"\n\n\n<p>\u5982\u679c\u60f3\u5c07\u8a0a\u865f\u5f9e A \u9ede\u50b3\u9001\u5230 B \u9ede\uff0c\u9700\u8981\u900f\u904e\u6578\u500b\u57fa\u5730\u53f0\u4f9d\u5e8f\u5354\u52a9\u50b3\u905e\u3002<\/p>\n\n\n\n<p>\u5c0d\u65bc\u6bcf\u500b\u57fa\u5730\u53f0\uff0c\u5df2\u77e5\u5176 (\u64fa\u653e\u4f4d\u7f6e d) \u548c (\u8a0a\u865f\u53ef\u5411\u53f3\u50b3\u9001\u7bc4\u570d r)\uff0c<br>\u4e5f\u5c31\u662f\u53ea\u8981\u88ab\u653e\u5728 d ~ d+r(\u5305\u542b) \u4f4d\u7f6e\u7bc4\u570d\u5167\u7684\u57fa\u5730\u53f0\uff0c\u7686\u53ef\u6536\u5230\u8a72\u57fa\u5730\u53f0\u7684\u8a0a\u865f\u3002<\/p>\n\n\n\n<p>\u7d66\u5b9a N \u500b\u7531\u5de6\u81f3\u53f3\u7684\u57fa\u5730\u53f0\uff0c<br>\u8acb\u5354\u52a9\u8a08\u7b97\u5982\u679c\u7531\u6700\u5de6\u5074\u4e5f\u5c31\u662f\u7de8\u865f 1 \u7684\u57fa\u5730\u53f0\u767c\u51fa\u8a0a\u865f\uff0c\u5411\u53f3\u6700\u9060\u53ef\u50b3\u905e\u5230\u54ea\u500b\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"288\" loading=\"lazy\" src=\"https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-3-1024x288.png\" alt=\"ZeroJudge N686 \u984c\u76ee\u6f14\u793a\u5716\" class=\"wp-image-975\" srcset=\"https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-3-1024x288.png 1024w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-3-300x84.png 300w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-3-768x216.png 768w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-3-1536x432.png 1536w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-3-18x5.png 18w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-3-50x14.png 50w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-3-100x28.png 100w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-3.png 1721w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>\u7b2c\u4e00\u884c\u6709\u4e00\u500b\u6b63\u6574\u6578 N\uff0c\u4ee3\u8868\u6709 N \u500b\u57fa\u5730\u53f0<br>1 \u2264 N \u2264 1000<br>\u7b2c\u4e8c\u884c\u6709 N \u500b\u975e\u8ca0\u6574\u6578 di\uff0c\u4ee3\u8868\u7b2c i \u500b\u57fa\u5730\u53f0\u6240\u5728\u4f4d\u7f6e<br>0 \u2264 d<sub>i<\/sub> \u2264 10<sup>9<\/sup><br>\u4e26\u4e14\u4fdd\u8b49 d<sub>1<\/sub> = 0 \u4e14 d<sub>1<\/sub> \u2264 d<sub>2<\/sub> \u2264 \u2026 \u2264 d<sub>N<\/sub><br>\u7b2c\u4e09\u884c\u6709 N \u500b\u975e\u8ca0\u6574\u6578 r<sub>i<\/sub>\uff0c\u4ee3\u8868\u7b2c i \u500b\u57fa\u5730\u53f0\u8a0a\u865f\u53ef\u5411\u53f3\u7bc4\u570d<br>0 \u2264 r<sub>i<\/sub> \u2264 10<sup>9<\/sup><\/td><td>\u7531\u6700\u5de6\u5074\u4e5f\u5c31\u662f\u7de8\u865f 1 \u7684\u57fa\u5730\u53f0\u767c\u51fa\u8a0a\u865f\uff0c<br>\u5411\u53f3\u6700\u9060\u53ef\u50b3\u905e\u5230\u7684\u4f4d\u7f6e<\/td><\/tr><tr><td>5<br>0 3 5 11 15<br>3 9 2 2 5<\/td><td>13<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u5c07\u6bcf\u4e00\u500b\u57fa\u5730\u53f0\u7684\u4e0b\u4e00\u500b\u57fa\u5730\u53f0\u4f4d\u7f6e\u7d00\u9304\u4e0b\u4f86\uff0c\u53ef\u4ee5\u4f7f\u7528\u9663\u5217\u7684\u65b9\u5f0f\u4f86\u7d00\u9304\uff0c\u9019\u908a\u547d\u540d\u53eb next\u3002\u53e6\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528 map&lt;int, int&gt; \u4f86\u7d00\u9304\u6bcf\u4e00\u500b\u57fa\u5730\u53f0\u53ef\u4ee5\u8dd1\u591a\u9060\uff0c\u9019\u908a\u547d\u540d\u53eb MAP\u3002<\/p>\n\n\n\n<p>\u8dd1\u4e00\u500b For\u8ff4\u5708 \u5f9e 0 \u5230 N-2\uff0c\u4e26\u4e14\u5ba3\u544a\u5169\u500b\u8b8a\u6578 pos = 0\u3001step = MAP[0]\uff0c\u5206\u5225\u4ee3\u8868\u76ee\u524d\u7684\u4f4d\u7f6e\u548c\u9084\u6709\u5e7e\u6b65\u53ef\u4ee5\u8d70\u3002\u5982\u679c pos + step &gt;= next[i]\uff0c\u4e5f\u5c31\u662f\u7576\u76ee\u524d\u4f4d\u7f6e\uff0b\u5269\u9918\u6b65\u6578\u53ef\u4ee5\u62b5\u9054\u4e0b\u4e00\u500b\u57fa\u5730\u53f0\u6642\uff0c\u5c07 pos \u66f4\u65b0\u6210 next[i]\uff0c\u4e26\u4e14\u5c07 step -= next[i] &#8211; pos\u3002\u4e4b\u5f8c\u8981\u4f86\u6bd4\u5c0d\u662f\u76ee\u524d\u5269\u9918\u7684\u6b65\u6578 step \u6bd4\u8f03\u591a\uff0c\u9084\u662f MAP[next[i]] \u4e5f\u5c31\u662f\u65b0\u57fa\u5730\u53f0\u63d0\u4f9b\u7684\u6b65\u6578\u6bd4\u8f03\u591a\uff0c\u5c07\u591a\u8005\u8a2d\u5b9a\u70ba\u65b0\u7684 step\u3002\u5982\u679c\u7121\u6cd5\u62b5\u9054\u4e0b\u4e00\u500b\u57fa\u5730\u53f0\uff0c\u5247\u5c07 For\u8ff4\u5708 Break \u6389\u3002<\/p>\n\n\n\n<p>\u8f38\u51fa\u7684\u6642\u5019\u56e0\u70ba\u53ef\u80fd\u6703\u6709\u5269\u9918\u7684\u6b65\u6578\uff0c\u6240\u4ee5\u662f\u8f38\u51fa pos + step\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=n686\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge N686: \u8a0a\u865f\u50b3\u905e<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;map&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    cin &gt;&gt; N;\n    vector&lt;int&gt;num, next;\n    map&lt;int, int&gt;MAP;\n    for (int i = 0; i&lt;N; i++) {\n        int tmp;\n        cin &gt;&gt; tmp;\n        num.push_back(tmp);\n        if (i != 0) next.push_back(tmp);\n    }\n    for (int i = 0; i&lt;N; i++) {\n        int tmp;\n        cin &gt;&gt; tmp;\n        MAP[num[i]] = tmp;\n    }\n    int pos = 0, step = MAP[0];\n    for (int i = 0; i&lt;N-1; i++) {\n        if (pos + step &gt;= next[i]) {\n            step -= next[i] - pos;\n            pos = next[i];\n            step = max(step, MAP[next[i]]);\n        }\n        else break;\n    }\n    cout &lt;&lt; pos + step &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/ZeroJudge N686\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u60f3\u5c07\u8a0a\u865f\u5f9e A \u9ede\u50b3\u9001\u5230 B \u9ede\uff0c\u9700\u8981\u900f\u904e\u6578\u500b\u57fa\u5730\u53f0\u4f9d\u5e8f\u5354\u52a9\u50b3\u905e\u3002 \u5c0d\u65bc\u6bcf\u500b\u57fa\u5730\u53f0\uff0c\u5df2\u77e5\u5176 (\u64fa\u653e\u4f4d\u7f6e d [&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":[6],"tags":[14,20,8,9],"class_list":["post-974","post","type-post","status-publish","format-standard","hentry","category-6","tag-map","tag-20","tag-8","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/974","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=974"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/974\/revisions"}],"predecessor-version":[{"id":997,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/974\/revisions\/997"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}