{"id":1045,"date":"2024-08-07T09:00:00","date_gmt":"2024-08-07T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1045"},"modified":"2024-07-03T23:29:17","modified_gmt":"2024-07-03T15:29:17","slug":"zerojudge-a565","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-a565\/","title":{"rendered":"ZeroJudge A565: p&amp;q"},"content":{"rendered":"\n\n\n<p>\u00a0\u300c\u773e\u88e1\u5c0b\u4ed6\uff08\u5979\uff09\u5343\u767e\u5ea6\uff0c\u9a40\u7136\u56de\u9996\uff0c\u90a3\u4eba\u537b\u5728\u71c8\u706b\u95cc\u73ca\u8655\u3002\u300d\u5982\u679c\u8b93\u4f60\u7576\u6708\u4e0b\u8001\u4eba\uff0c\u4f60\u80fd\u5920\u628a\u770b\u5c0d\u773c\u7684\u5169\u500b\u6709\u7de3\u4eba\u76e1\u91cf\u6e4a\u6210\u4e00\u5c0d\uff0c\u4e0d\u8981\u8b93\u907a\u61be\u767c\u751f\u55ce\uff1f\u6211\u5011\u5c07\u7d66\u4f60\u4e00\u4efd\u7b49\u5f85\u914d\u5c0d\u7684\u540d\u55ae\uff0c\u5176\u4e2d\u300cp\u300d\u4ee3\u8868\u7537\u751f\uff0c\u300cq\u300d\u4ee3\u8868\u5973\u751f\uff0c\u914d\u5c0d\u7684\u689d\u4ef6\u5f88\u7c21\u55ae\uff0c\u53ea\u8981 p \u8ddf q \u7684\u4f4d\u7f6e\u662f\u300c\u9762\u5c0d\u9762\u300d\uff08\u4ea6\u5373\u300cpq\u300d\uff09\uff0c\u5c31\u4ee3\u8868\u5f7c\u6b64\u76f8\u770b\u5169\u4e0d\u53ad\uff0c\u53ef\u88ab\u8996\u70ba\u4e00\u5c0d\uff0c\u5176\u4ed6\u7684\u72c0\u614b\uff0c\u5982\u80cc\u5c0d\u80cc (\u4ea6\u5373\u300cqp\u300d\u3001\u300cpp\u300d\u6216\u300cqq\u300d\uff09\uff0c\u5247\u4e0d\u80fd\u914d\u5c0d\u6210\u529f\u3002\u6210\u529f\u914d\u5c0d\u5f8c\uff0c\u8a72 pq \u5c0d\u5c31\u88ab\u79fb\u51fa\u7b49\u5019\u914d\u5c0d\u540d\u55ae\uff0c\u8b93\u5176\u4ed6\u7684 p \u8207 q \u53ef\u4ee5\u6709\u6a5f\u6703\u7e7c\u7e8c\u914d\u5c0d\u3002\u4f60\u7684\u76ee\u6a19\u5c31\u662f\u76e1\u91cf\u627e\u51fa\u6240\u6709\u53ef\u4ee5\u914d\u6210\u5c0d\u7684 p \u8207 q\u3002\u80fd\u5426\u5713\u6eff\u9054\u6210\u4efb\u52d9\uff0c\u5c31\u9760\u4f60\u667a\u6167\u7684\u5b89\u6392\uff01\u9858\u5929\u4e0b\u6709\u60c5\u4eba\u7d42\u6210\u7737\u5c6c\uff01<\/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>\u7b2c\u4e00\u884c\u662f\u4e00\u500b\u6574\u6578 N\uff0c\u4ee3\u8868\u6709 N \u7d44 (\u884c) \u7684\u7b49\u5019\u914d\u5c0d\u540d\u55ae\u3002<br>\u6bcf\u4e00\u7d44\u540d\u55ae\u4e2d\uff0cp \u8207 q \u4e4b\u9593\u53ef\u80fd\u76f8\u9130\u6216\u8005\u4ee5\u300c.\u300d\u5206\u9694\uff0c\u300c.\u300d\u7684\u6578\u91cf\u591a\u5be1\u4e0d\u5b9a\uff0c\u4f46\u4e0d\u5f71\u97ff p \u8207 q \u7684\u914d\u5c0d (\u8ddd\u96e2\u4e0d\u662f\u554f\u984c\uff01\uff09\uff0c\u4ea6\u5373\u9664\u4e86 pq \u4ee5\u5916\uff0cp.q\u3001p&#8230;.q \u7b49\u90fd\u53ef\u4ee5\u914d\u6210\u5c0d\u3002<\/td><td>\u8f38\u51fa\u80fd\u6210\u529f\u914d\u6210\u5c0d\u7684\u6700\u5927\u7e3d\u6578\uff0c\u8f38\u51fa\u7684\u6bcf\u4e00\u884c\u5c0d\u61c9\u4e00\u7d44\u7b49\u5019\u540d\u55ae\u3002<\/td><\/tr><tr><td>2<br>..p..p.p\u2026q.q.<br>.p\u2026qq..p.pq.p..q.qpp..qpq<\/td><td>2<br>6<\/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\u4e00\u6574\u884c\u4ee5\u5b57\u4e32\u7684\u65b9\u5f0f\u6536\u8d77\u4f86\uff0c\u4e26\u4e14\u5ba3\u544a\u4e00\u500b Vector&lt;char>\uff0c\u5c0d\u5b57\u4e32\u4e2d\u7684\u6bcf\u4e00\u500b\u5b57\u5143\u9032\u884c\u5224\u65b7\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u76ee\u524d\u5b57\u5143\u662f\u300cq\u300d\u7684\u8a71\uff0c\u5247\u8981\u5148\u5224\u65b7 Vector \u4e2d\u6709\u6c92\u6709\u8cc7\u6599\uff0c\u5982\u679c\u6709\u7684\u8a71\uff0c\u5224\u65b7\u6700\u5f8c\u4e00\u500b\u8cc7\u6599\u662f\u5426\u70ba\u300cp\u300d\uff0c\u5982\u679c\u662f\u7684\u8a71\u5c07\u7b54\u6848 +1 \u4e26\u4e14\u5c07 Vector \u9032\u884c pop_back()\u3002\u5982\u679c\u4e0a\u9762\u7684\u4e0d\u6210\u7acb\u5247\u5c07\u76ee\u524d\u5b57\u5143 Push_Back \u5230 Vector \u4e2d\u3002\u300c.\u300d\u9019\u500b\u5b57\u5143\u4e00\u5f8b\u4e0d\u505a\u5224\u65b7\u4e5f\u4e0d\u7528\u5b58\u5230 Vector \u4e2d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a565\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge A565: p&amp;q\u7684\u9082\u9005<\/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;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    for (int i = 0; i&lt;N; i++) {\n        string str;\n        cin &gt;&gt; str;\n        vector&lt;char&gt;v;\n        int ans = 0;\n        for (int j = 0; j&lt;str.length(); j++) {\n            const char ch = str[j];\n            if (ch != &#39;.&#39;) {\n                if (ch == &#39;q&#39; && !v.empty()) {\n                    if (v[v.size()-1] == &#39;p&#39;) {\n                        ans++;\n                        v.pop_back();\n                        continue;\n                    }\n                }\n                v.push_back(ch);\n            }\n        }\n        cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge A565\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0\u300c\u773e\u88e1\u5c0b\u4ed6\uff08\u5979\uff09\u5343\u767e\u5ea6\uff0c\u9a40\u7136\u56de\u9996\uff0c\u90a3\u4eba\u537b\u5728\u71c8\u706b\u95cc\u73ca\u8655\u3002\u300d\u5982\u679c\u8b93\u4f60\u7576\u6708\u4e0b\u8001\u4eba\uff0c\u4f60\u80fd\u5920\u628a\u770b\u5c0d\u773c\u7684\u5169\u500b\u6709\u7de3\u4eba\u76e1\u91cf\u6e4a [&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":[38,8,11,9],"class_list":["post-1045","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-vector","tag-8","tag-11","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1045","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=1045"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1045\/revisions"}],"predecessor-version":[{"id":1047,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1045\/revisions\/1047"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}