{"id":287,"date":"2024-04-27T12:18:26","date_gmt":"2024-04-27T04:18:26","guid":{"rendered":"https:\/\/seanxd.com\/?p=287"},"modified":"2024-04-27T12:18:28","modified_gmt":"2024-04-27T04:18:28","slug":"zerojudge-k731","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-k731\/","title":{"rendered":"ZeroJudge K731: \u8def\u5f91\u5075\u6e2c"},"content":{"rendered":"\n\n\n<p class=\"\">\u7d66\u4e00\u500b\u4e8c\u7dad\u5e73\u9762\uff0c\u5ea7\u6a19\u5982\u540c\u6578\u5b78\u7684\u4e8c\u7dad\u5ea7\u6a19 (\uff39\u6b63\u70ba\u5317\uff0c\uff38\u6b63\u70ba\u6771)\u3002<strong>\u8d77\u59cb\u4f4d\u7f6e\u5728 (0, 0)<\/strong>\uff0c\u63a5\u4e0b\u4f86\u6703\u6709 N \u500b\u5ea7\u6a19\uff0c\u4f60\u9700\u8981<strong>\u6309\u7167\u9019\u4e9b\u5ea7\u6a19\u9ede\u7684\u9806\u5e8f\u79fb\u52d5<\/strong>\uff0c\u4fdd\u8b49\u50c5\u6703<strong>\u5782\u76f4\u6216\u6c34\u5e73\u65b9\u5411<\/strong>\u4e0a\u79fb\u52d5\uff0c\u4e0d\u6703\u659c\u5411\u79fb\u52d5\uff0c\u4e14\u7b2c\u4e00\u500b\u9ede\u4fdd\u8b49\u4e00\u5b9a\u662f\uff38\u8ef8\u6b63\u7684\u4f4d\u7f6e (\u521d\u59cb\u65b9\u5411\u5411\u53f3)\u3002<\/p>\n\n\n\n<p class=\"\">\u8acb<strong>\u8f38\u51fa\u9019\u689d\u8def\u5f91\u4e2d\uff0c\u5de6\u8f49\u3001\u53f3\u8f49\u3001\u8ff4\u8f49\u7684\u500b\u6578\u5206\u5225\u70ba\u591a\u5c11<\/strong>\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>\u7b2c\u4e00\u884c\u8f38\u5165\u4e00\u500b\u6b63\u6574\u6578 N\uff0c\u63a5\u4e0b\u4f86\u6709 N \u884c\uff0c\u6bcf\u4e00\u884c\u90fd\u6709\u5169\u500b\u6b63\u6574\u6578 x \u548c y\u3002\u4fdd\u8b49\u7684\u662f\u76f8\u9130\u5169\u500b\u9ede\u7684\u5ea7\u6a19\u5dee\u503c\u4e0d\u8d85\u904e 100\u3002<\/td><td>\u8f38\u51fa\u4e09\u500b\u6b63\u6574\u6578\uff0c\u5206\u5225\u4ee3\u8868\u5de6\u8f49\u3001\u53f3\u8f49\u3001\u8ff4\u8f49\u7684\u6b21\u6578\u3002<\/td><\/tr><tr><td>2<br>2  0<br>2  1<\/td><td>1  0  0<\/td><\/tr><tr><td>9<br>4  0<br>4  9<br>4  8<br>4  10<br>4  2<br>4  3<br>6  3<br>6  10<br>6  9<\/td><td>2  1  5<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge K731 \u7bc4\u4f8b\u6e2c\u8cc7<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\">\u53ef\u4ee5\u908a\u6536\u8cc7\u6599\u908a\u505a\u8a08\u7b97\uff0c\u5224\u65b7 x \u548c y \u7684\u503c\u548c\u76ee\u524d\u4f4d\u7f6e\u662f\u589e\u52a0\u9084\u662f\u6e1b\u5c11\u4f86\u5224\u65b7\u8981\u600e\u9ebc\u8f49\u5f4e\u6216\u8005\u4e0d\u7528\u8f49\u5f4e\u3002\u8a2d\u5b9a\u4e00\u500b<strong>\u76ee\u524d x \u548c y \u5ea7\u6a19\u7684 Pair&lt;int, int><\/strong>\uff0c\u6bcf\u4e00\u6b21\u5224\u65b7\u5b8c\u8f49\u5f4e\u65b9\u5411\u5c31\u5c07\u6536\u5230\u7684 x \u548c y \u8a2d\u5b9a\u70ba\u76ee\u524d\u7684 x \u548c y \u5ea7\u6a19\u7684 Pair\u3002<\/p>\n\n\n\n<p class=\"\">\u53ef\u4ee5\u8a2d\u5b9a\u4e00\u500b<strong>\u5b57\u4e32<\/strong>\u4f86\u5b58<strong>\u76ee\u524d\u9762\u671d\u7684\u65b9\u5411<\/strong>\uff0c\u518d\u5229\u7528 <strong>If<\/strong> \u5224\u65b7 <strong>x \u548c y \u7684\u589e\u6e1b<\/strong>\u4f86\u770b\u8981\u5c07\u65b9\u5411\u5b57\u4e32\u8b8a\u6210\u54ea\u4e00\u500b\u65b9\u5411\uff0c\u4e26\u4e14\u53ef\u4ee5\u4f7f\u7528 <strong>Map<\/strong> \u4f86\u7d00\u9304\u6bcf\u4e00\u7a2e\u8f49\u5f4e\u65b9\u5f0f\u7e3d\u5171\u7528\u4e86\u5e7e\u6b21\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=k731\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge K731: \u8def\u5f91\u5075\u6e2c<\/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;map&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    pair&lt;int, int&gt; start;\n    start.first = 0;\n    start.second = 0;\n    string direction = &quot;right&quot;;\n    map&lt;string, int&gt;MAP;\n    for (int i = 0; i&lt;N; i++)\n    {\n        int x, y;\n        cin &gt;&gt; x &gt;&gt; y;\n        if (x &gt; start.first)\n        {\n            if (direction == &quot;left&quot;) MAP[&quot;return&quot;]++;\n            else if (direction == &quot;up&quot;) MAP[&quot;right&quot;]++;\n            else if (direction == &quot;down&quot;) MAP[&quot;left&quot;]++;\n            direction = &quot;right&quot;;\n        }\n        else if (x &lt; start.first)\n        {\n            if (direction == &quot;right&quot;) MAP[&quot;return&quot;]++;\n            else if (direction == &quot;down&quot;) MAP[&quot;right&quot;]++;\n            else if (direction == &quot;up&quot;) MAP[&quot;left&quot;]++;\n            direction = &quot;left&quot;;\n        }\n        else if (y &gt; start.second)\n        {\n            if (direction == &quot;down&quot;) MAP[&quot;return&quot;]++;\n            else if (direction == &quot;left&quot;) MAP[&quot;right&quot;]++;\n            else if (direction == &quot;right&quot;) MAP[&quot;left&quot;]++;\n            direction = &quot;up&quot;;\n        }\n        else\n        {\n            if (direction == &quot;up&quot;) MAP[&quot;return&quot;]++;\n            else if (direction == &quot;right&quot;) MAP[&quot;right&quot;]++;\n            else if (direction == &quot;left&quot;) MAP[&quot;left&quot;]++;\n            direction = &quot;down&quot;;\n        }\n        start.first = x;\n        start.second = y;\n    }\n    cout &lt;&lt; MAP[&quot;left&quot;] &lt;&lt; &quot; &quot; &lt;&lt; MAP[&quot;right&quot;] &lt;&lt; &quot; &quot; &lt;&lt; MAP[&quot;return&quot;] &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/ZeroJudge K731\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7d66\u4e00\u500b\u4e8c\u7dad\u5e73\u9762\uff0c\u5ea7\u6a19\u5982\u540c\u6578\u5b78\u7684\u4e8c\u7dad\u5ea7\u6a19 (\uff39\u6b63\u70ba\u5317\uff0c\uff38\u6b63\u70ba\u6771)\u3002\u8d77\u59cb\u4f4d\u7f6e\u5728 (0, 0)\uff0c\u63a5\u4e0b\u4f86\u6703\u6709 N \u500b\u5ea7 [&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":[25],"tags":[14,23,8,11,9],"class_list":["post-287","post","type-post","status-publish","format-standard","hentry","category-ioi-apcs","tag-map","tag-pair","tag-8","tag-11","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/287","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=287"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/287\/revisions"}],"predecessor-version":[{"id":289,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/287\/revisions\/289"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}