{"id":398,"date":"2024-04-29T16:28:42","date_gmt":"2024-04-29T08:28:42","guid":{"rendered":"https:\/\/seanxd.com\/?p=398"},"modified":"2024-04-29T16:28:45","modified_gmt":"2024-04-29T08:28:45","slug":"zerojudge-e924","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-e924\/","title":{"rendered":"ZeroJudge E924: Pairing Brackets"},"content":{"rendered":"\n\n\n<p class=\"\">\u8acb\u64b0\u5beb\u4e00\u500b\u7a0b\u5f0f\uff0c\u8f38\u5165\u4e00\u884c\u5b57\u4e32\u5f8c\uff0c\u8f38\u51fa\u8a72\u5b57\u4e32\u7684\u62ec\u865f\u914d\u5c0d\u662f\u5426\u6b63\u78ba\u3002<br>\u8981\u6aa2\u67e5\u7684\u62ec\u865f\u6709\u5713\u62ec\u865f ()\u3001\u65b9\u62ec\u865f []\u3001\u5c0f\u65bc\u5927\u65bc\u62ec\u865f &lt;> \u548c\u66f2\u62ec\u865f {}\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>\u8f38\u5165\u7b2c\u4e00\u884c\u6709\u4e00\u500b\u6b63\u6574\u6578 T (1 \u2264 T \u2264 1000\uff09\uff0c<br>\u4ee3\u8868\u63a5\u4e0b\u4f86\u5171\u6709 T \u884c\u5b57\u4e32\u8981\u9a57\u8b49\u3002<br>\u63a5\u4e0b\u4f86\u4f9d\u5e8f\u6709 T \u884c\uff0c\u6bcf\u884c\u70ba\u9700\u8981\u9a57\u8b49\u62ec\u865f\u914d\u5c0d\u7684\u5b57\u4e32 s\uff0c\u5b57\u4e32\u4e2d<strong>\u53ea\u6703\u51fa\u73fe ()\u3001[]\u3001&lt;> \u548c {}<\/strong>\u3002<\/td><td>\u82e5\u914d\u5c0d\u6210\u529f\u8f38\u51fa\u300cY\u300d<br>\u82e5\u914d\u5c0d\u5931\u6557\u8f38\u51fa\u300cN\u300d<\/td><\/tr><tr><td>4<br>{()&lt;>}[]<br>(){<br>{(})<br>())<\/td><td>Y<br>N<br>N<br>N<\/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=\"\">\u5982\u679c\u5b57\u4e32\u9577\u5ea6\u70ba\u5947\u6578\u76f4\u63a5\u8f38\u51fa N\u3002\u53ef\u4ee5<strong>\u4f7f\u7528 Stack \u7684\u6982\u5ff5\u505a\u9019\u984c<\/strong>\uff0c\u5982\u679c<strong>\u8dd1\u5230\u7684\u5b57\u5143\u662f\u5de6\u62ec\u865f\u7684\u8a71\u5c31\u5c07\u9019\u500b\u5b57\u5143 Push_Back \u5230\u4e00\u500b Vector \u4e2d<\/strong>\uff0c\u5982\u679c<strong>\u8dd1\u5230\u4e00\u500b\u53f3\u62ec\u865f\u5247\u5224\u65b7 Vector \u4e2d\u7684\u6700\u5f8c\u4e00\u500b\u8cc7\u6599\u662f\u5426\u80fd\u548c\u9019\u500b\u53f3\u62ec\u865f\u914d\u5c0d<\/strong>\u3002\u5982\u679c\u914d\u5c0d<strong>\u6210\u529f\u90a3\u5c31\u4f7f\u7528 Pop_Back \u5c07 Vector \u6700\u5f8c\u4e00\u500b\u8cc7\u6599\u522a\u9664<\/strong>\uff0c\u5982\u679c\u914d\u5c0d<strong>\u5931\u6557\u5c31\u76f4\u63a5\u8f38\u51fa\u300cN\u300d\u7136\u5f8c Break \u6389 For\u8ff4\u5708<\/strong>\u3002\u53e6\u5916<strong>\u5224\u65b7\u7684\u6642\u5019\u4e5f\u9700\u8981\u6ce8\u610f\u4e00\u4e0bVector\u5167\u76ee\u524d\u6709\u6c92\u6709\u8cc7\u6599\uff0c\u5982\u679cVector\u7684Size\u662f0\u7684\u8a71\u4ee3\u8868\u7a81\u7136\u6709\u4e00\u500b\u53f3\u62ec\u865f\u51fa\u73fe<\/strong>\uff0c\u76f4\u63a5\u8f38\u51faN\u7136\u5f8cBreak\u3002For\u8ff4\u5708\u7d50\u675f\u5f8c\u4e5f\u9700\u8981\u5224\u65b7Vector\u4e2d\u9084\u6709\u6c92\u6709\u6b98\u7559\u7684\u5de6\u62ec\u865f\uff0c\u5982\u679c\u6709\u7684\u8a71\u540c\u6a23\u4e5f\u662f\u8f38\u51faN\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=e924\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge E924: \u62ec\u865f\u914d\u5c0d<\/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;\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    map&lt;char, char&gt;MAP;\n    MAP[&#39;)&#39;] = &#39;(&#39;;\n    MAP[&#39;]&#39;] = &#39;[&#39;;\n    MAP[&#39;&gt;&#39;] = &#39;&lt;&#39;;\n    MAP[&#39;}&#39;] = &#39;{&#39;;\n    for (int i = 0; i&lt;N; i++)\n    {\n        string str;\n        cin &gt;&gt; str;\n        if (str.length() % 2 != 0) cout &lt;&lt; &quot;N\\n&quot;;\n        else\n        {\n            vector&lt;char&gt;v;\n            bool ok = true;\n            for (int j = 0; j&lt;str.length(); j++)\n            {\n                char ch = str[j];\n                if (ch == &#39;(&#39; || ch == &#39;[&#39; || ch == &#39;&lt;&#39; || ch == &#39;{&#39;) v.push_back(ch);\n                else\n                {\n                    if (v.size() == 0)\n                    {\n                        ok = false;\n                        cout &lt;&lt; &quot;N\\n&quot;;\n                        break;\n                    }\n                    if (v[int(v.size())-1] == MAP[str[j]]) v.pop_back();\n                    else\n                    {\n                        ok = false;\n                        cout &lt;&lt; &quot;N\\n&quot;;\n                        break;\n                    }\n                }\n            }\n            if (ok && v.size() != 0) cout &lt;&lt; &quot;N\\n&quot;;\n            else if (ok) cout &lt;&lt; &quot;Y\\n&quot;;\n        }\n    }\n}\n\n\/\/ZeroJudge E924\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8acb\u64b0\u5beb\u4e00\u500b\u7a0b\u5f0f\uff0c\u8f38\u5165\u4e00\u884c\u5b57\u4e32\u5f8c\uff0c\u8f38\u51fa\u8a72\u5b57\u4e32\u7684\u62ec\u865f\u914d\u5c0d\u662f\u5426\u6b63\u78ba\u3002\u8981\u6aa2\u67e5\u7684\u62ec\u865f\u6709\u5713\u62ec\u865f ()\u3001\u65b9\u62ec\u865f []\u3001\u5c0f\u65bc\u5927 [&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":[14,20,8,11,9],"class_list":["post-398","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-map","tag-20","tag-8","tag-11","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=398"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/398\/revisions"}],"predecessor-version":[{"id":399,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/398\/revisions\/399"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}