{"id":1202,"date":"2024-10-05T09:00:00","date_gmt":"2024-10-05T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1202"},"modified":"2024-09-06T01:52:06","modified_gmt":"2024-09-05T17:52:06","slug":"zerojudge-b684","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-b684\/","title":{"rendered":"ZeroJudge B684: \u72d7\u72d7\u904a\u6232"},"content":{"rendered":"\n\n\n<p>\u5c0f\u5713\u990a\u4e86\u4e00\u96bb\u53ef\u611b\u7684\u5c0f\u9ed1\u72d7\uff0c\u4f46\u7531\u65bc\u4e00\u6642\u60f3\u4e0d\u5230\u4ec0\u9ebc\u7279\u5225\u7684\u540d\u5b57\uff0c\u56e0\u6b64\u5c31\u53eb\u7260\u300cCuteBlack Dog\u300d\uff0c\u7c21\u7a31 CBD\u3002CBD \u975e\u5e38\u8070\u660e\uff0c\u53ef\u4ee5\u8a8d\u5f97\u963f\u62c9\u4f2f\u6578\u5b57\uff0c\u4e5f\u56e0\u6b64\u5f97\u5230\u5c0f\u5713\u7684\u937e\u611b\u3002<\/p>\n\n\n\n<p>\u5728\u5c0f\u5713\u7684\u7d30\u5fc3\u7167\u6599\u4e4b\u4e0b\uff0cCBD \u65e5\u6f38\u767c\u798f\uff0c\u5c0f\u5713\u773c\u898b\u9019\u6a23\u4e8b\u60c5\u4e0d\u592a\u5999\uff0c\u65bc\u662f\u8a2d\u8a08\u4e00\u500b\u904a\u6232\u8b93 CBD \u5728\u73a9\u7684\u6642\u5019\u53ef\u4ee5\u9806\u4fbf\u904b\u52d5\u3002<\/p>\n\n\n\n<p>\u5c0f\u5713\u8a2d\u8a08\u7684\u904a\u6232\u662f\u9019\u6a23\u7684\uff1a\u4ed6\u5148\u6e96\u5099\u4e86 N \u5f35\u7d19\u5361\uff0c\u4e0a\u9762\u4f9d\u5e8f\u5beb\u8457 1 \u81f3 N \u7684\u5404\u500b\u6b63\u6574\u6578\uff0c\u4e26\u5c07\u9019\u4e9b\u7d19\u5361\u5728\u5730\u4e0a\u4e82\u5e8f\u7684\u7531\u5de6\u5230\u53f3\u6392\u6210\u4e00\u5217\u3002\u63a5\u8457\u4ed6\u8b93 CBD \u5148\u7531\u6700\u5de6\u908a\u7684\u7d19\u5361\u8dd1\u5230\u6700\u53f3\u908a\u7684\u7d19\u5361\uff0c\u518d\u5f9e\u6700\u53f3\u908a\u8dd1\u56de\u6700\u5de6\u908a\uff0c\u4e0d\u65b7\u6298\u8fd4\uff0c\u4e26\u898f\u5b9a\u9014\u4e2d\u53ea\u8981\u9047\u5230\u5beb\u8457\u76ee\u524d\u6240\u5269\u9918\u7684\u7d19\u5361\u4e2d\uff0c\u6578\u503c\u6700\u5c0f\u7684\u90a3\u5f35\u7d19\u5361\uff0c\u5c31\u8981\u5c07\u8a72\u7d19\u5361\u53fc\u8d70\uff0c\u5426\u5247\u4e0d\u80fd\u628a\u8a72\u7d19\u5361\u53fc\u8d70\u3002<\/p>\n\n\n\n<p>\u8209\u4f8b\u4f86\u8aaa\uff0c\u5047\u8a2d\u4e00\u958b\u59cb\u5171\u6709 5 \u5f35\u5361\u7247\uff0c\u7531\u5de6\u800c\u53f3\u4f9d\u5e8f\u70ba 1, 4, 2, 5, 3\uff0c\u5247 CBD \u7b2c\u4e00\u6b21\u7531\u5de6\u7aef\u8dd1\u5230\u53f3\u7aef\u6642\uff0c\u5ef6\u8def\u6703\u53fc\u8d70 1, 2, 3 \u4e09\u5f35\u7d19\u5361\uff0c\u6298\u8fd4\u5f80\u5de6\u8dd1\u6642\u6703\u53fc\u8d70 4\uff0c\u53c8\u6298\u8fd4\u5f80\u53f3\u8dd1\u6642\u518d\u628a 5 \u53fc\u8d70\u3002<\/p>\n\n\n\n<p>\u5c0f\u5713\u60f3\u8acb\u4f60\u5e6b\u4ed6\u7b97\u4e00\u4e0b\uff0c\u7d66\u5b9a\u4e00\u958b\u59cb\u7684\u7d19\u5361\u6392\u5217\u65b9\u5f0f\uff0cCBD \u4e00\u5171\u81f3\u5c11\u9700\u8981\u6539\u8b8a\u5e7e\u6b21\u65b9\u5411\u624d\u80fd\u628a\u6240\u6709\u7d19\u5361\u90fd\u53fc\u8d70\u5462\uff1f<\/p>\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>\u6e2c\u8a66\u8cc7\u6599\u7684\u8f38\u5165\u5171\u6709\u5169\u5217\u3002<br>\u7b2c\u4e00\u5217\u70ba\u6b63\u6574\u6578 N\uff0c\u8868\u793a\u7d19\u5361\u7684\u6578\u91cf\u3002<br>\u7b2c\u4e8c\u5217\u5305\u542b N \u500b\u6b63\u6574\u6578\uff0c\u4ee5\u7a7a\u767d\u9694\u958b\uff0c\u8868\u793a\u7531\u5de6\u5230\u53f3\u7d19\u5361\u4e0a\u6240\u5beb\u7684\u6578\u503c\uff0c\u4fdd\u8b49 1 \u81f3 N \u90fd<br>\u6703\u6070\u597d\u51fa\u73fe\u4e00\u6b21\u3002<\/td><td><br>\u8acb\u8f38\u51fa\u4e00\u5217\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u500b\u6574\u6578\uff0c\u70ba CBD \u6298\u8fd4 (\u6539\u8b8a\u65b9\u5411) \u7684\u6b21\u6578\u3002<\/td><\/tr><tr><td>2<br>1 2<\/td><td>0<\/td><\/tr><tr><td>5<br>1 4 2 5 3<\/td><td>2<\/td><\/tr><tr><td>4<br>4 3 2 1<\/td><td>1<\/td><\/tr><tr><td>1<br>1<\/td><td>0<\/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\u8cc7\u6599\u7528 Pair \u7684\u65b9\u5f0f\u6536\u8d77\u4f86\uff0c\u7b2c\u4e00\u500b\u6b04\u4f4d\u662f\u76ee\u524d\u4f4d\u7f6e\u7684\u6578\u5b57\uff0c\u7b2c\u4e8c\u500b\u6b04\u4f4d\u662f\u9019\u500b\u6578\u5b57\u7684\u4f4d\u7f6e\u3002\u5c07\u9019\u4e9b\u8cc7\u6599\u4f7f\u7528\u9663\u5217\u6536\u8d77\u4f86\uff0c\u4e26\u4e14\u9032\u884c\u6392\u5e8f\u3002\u6392\u5e8f\u904e\u5f8c\uff0c\u5c07\u9663\u5217\u5f9e\u982d\u8dd1\u5230\u5c3e\uff0c\u4e26\u4e14\u7d00\u9304\u76ee\u524d\u662f\u5f80\u53f3\u8d70\u9084\u662f\u5f80\u5de6\u8d70\uff0c\u5982\u679c\u76ee\u524d\u6578\u5b57\u7684\u4f4d\u7f6e\u662f\u76ee\u524d\u4f4d\u7f6e\u7684\u53cd\u65b9\u5411\uff0c\u5247\u5c07\u7b54\u6848 +1 \u4e14\u63db\u65b9\u5411\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=b684\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge B684: \u72d7\u72d7\u904a\u6232<\/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;algorithm&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; num[1000005] = {};\n    for (int i = 0; i&lt;N; i++) {\n        int tmp;\n        cin &gt;&gt; tmp;\n        num[i] = make_pair(tmp, i);\n    }\n    sort(num, num+N);\n    string sign = &quot;Big&quot;;\n    int position = 0, ans = 0;\n    for (int i = 0; i&lt;N; i++) {\n        if (sign == &quot;Big&quot;) {\n            if (num[i].second &gt;= position) position = num[i].second;\n            else {\n                ans++;\n                sign = &quot;Small&quot;;\n                position = num[i].second;\n            }\n        }\n        else {\n            if (num[i].second &lt; position) position = num[i].second;\n            else {\n                ans++;\n                sign = &quot;Big&quot;;\n                position = num[i].second;\n            }\n        }\n    }\n    cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/ZeroJudge B684\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u5713\u990a\u4e86\u4e00\u96bb\u53ef\u611b\u7684\u5c0f\u9ed1\u72d7\uff0c\u4f46\u7531\u65bc\u4e00\u6642\u60f3\u4e0d\u5230\u4ec0\u9ebc\u7279\u5225\u7684\u540d\u5b57\uff0c\u56e0\u6b64\u5c31\u53eb\u7260\u300cCuteBlack Dog\u300d\uff0c\u7c21\u7a31 CB [&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":[29],"tags":[23,20,8,11,19,9],"class_list":["post-1202","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-pair","tag-20","tag-8","tag-11","tag-19","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1202","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=1202"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1202\/revisions"}],"predecessor-version":[{"id":1204,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1202\/revisions\/1204"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=1202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=1202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=1202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}