{"id":207,"date":"2025-03-24T14:36:13","date_gmt":"2025-03-24T06:36:13","guid":{"rendered":"http:\/\/m.qzcy2.top\/?p=207"},"modified":"2025-03-25T17:19:46","modified_gmt":"2025-03-25T09:19:46","slug":"%e7%89%9b%e5%ae%a2%e5%91%a8%e8%b5%9b86","status":"publish","type":"post","link":"https:\/\/m.qzcy2.top\/index.php\/2025\/03\/24\/%e7%89%9b%e5%ae%a2%e5%91%a8%e8%b5%9b86\/","title":{"rendered":"\u725b\u5ba2\u5468\u8d5b86"},"content":{"rendered":"<h1>\u8bf4\u660e<\/h1>\n<p>\u6b64\u6587\u7ae0\u4ec5\u4f5c\u8005\u4e2a\u4eba\u89c1\u89e3\u3002\u539f\u9898\u94fe\u63a5<a href=\"https:\/\/ac.nowcoder.com\/acm\/contest\/104637\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/ac.nowcoder.com\/acm\/contest\/104637<\/a><\/p>\n<h1>A.\u5c0f\u82ef\u8dd1\u5916\u5356<\/h1>\n<h2>\u9898\u76ee\u63cf\u8ff0<\/h2>\n<ul>\n<li>\u5c0f\u82ef\u53d1\u73b0\u81ea\u5df1\u5e73\u5747\u8dd1\u4e00\u5355\u5916\u5356\u53ef\u4ee5\u8d5a\u00a0<span class=\"katex\"><span class=\"katex-mathml\">xx<\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"mord mathdefault\">x<\/span><\/span><\/span><\/span>\u00a0\u5143\uff0c\u4e8e\u662f\uff0c\u4ed6\u7ed9\u81ea\u5df1\u5b9a\u4e0b\u4e86\u76ee\u6807\uff1a\u6bcf\u5929\u81f3\u5c11\u9700\u8981\u8d5a\u591f <span class=\"katex\"><span class=\"katex-mathml\">yy<\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"mord mathdefault\">y<\/span><\/span><\/span><\/span> \u5143\u3002\u4ed6\u60f3\u77e5\u9053\uff0c\u81ea\u5df1\u6bcf\u5929\u81f3\u5c11\u9700\u8981\u8dd1\u51e0\u5355\uff0c\u624d\u80fd\u8fbe\u6210\u4ed6\u5b9a\u4e0b\u7684\u76ee\u6807\u3002\u8bf7\u4f60\u5e2e\u4ed6\u7b97\u4e00\u7b97\u5427\u3002<\/li>\n<\/ul>\n<h2>\u601d\u8def<\/h2>\n<ul>\n<li><span style=\"color: #008000;\">\u8bed\u6cd5\u9898\uff0c\u5411\u4e0a\u53d6\u6574\u5373\u53ef\u3002<span style=\"color: #0000ff;\">\u65f6\u95f4\u590d\u6742O(1)\u3002<\/span><\/span><\/li>\n<\/ul>\n<h2>\u4ee3\u7801<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">void solve()\r\n{\r\n   int x , y;\r\n   cin &gt;&gt; x &gt;&gt; y;\r\n   cout &lt;&lt; (y % x == 0 ? y \/ x : (y \/ x) + 1) &lt;&lt; endl;\r\n}<\/pre>\n<h1>B.\u5c0f\u82ef\u7684\u533a\u95f4\u5220\u9664<\/h1>\n<h2>\u9898\u76ee\u63cf\u8ff0<\/h2>\n<ul>\n<li>\u5c0f\u82ef\u6709\u4e00\u4e2a\u7531 n \u4e2a\u6574\u6570\u7ec4\u6210\u7684\u6570\u7ec4 {a_1, a_2, ..., a_n}\uff0c\u4ed6\u60f3\u8981\u4f7f\u5f97\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u548c\u6700\u5927\u3002\u4e3a\u6b64\uff0c\u5c0f\u82ef\u53ef\u4ee5\u8fdb\u884c\u4efb\u610f\u6b21\u4ee5\u4e0b\u64cd\u4f5c\uff08\u4e5f\u53ef\u4ee5\u4e0d\u64cd\u4f5c\uff09\uff1a<br \/>\n\u9009\u62e9\u4e00\u4e2a\u957f\u5ea6\u4e0d\u8d85\u8fc7 k \u7684\u533a\u95f4 [l, r] (1 \u2264 l \u2264 r \u2264 n; r - l + 1 \u2264 k)\uff0c\u5c06 a_l, a_{l+1}, ..., a_r \u8fd9\u6bb5\u5143\u7d20\u5220\u9664\uff0c\u5e76\u5c06\u5176\u4f59\u5143\u7d20\u6309\u7167\u539f\u6709\u987a\u5e8f\u524d\u540e\u62fc\u63a5\u8d77\u6765\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u64cd\u4f5c\u540e\u6570\u7ec4\u53d8\u4e3a\uff1a<br \/>\na_1, a_2, ..., a_{l-1}, a_{r+1}, ..., a_n\u3002<br \/>\n\u5c0f\u82ef\u60f3\u77e5\u9053\uff0c\u5728\u53ef\u4ee5\u8fdb\u884c\u4efb\u610f\u6b21\u4e0a\u8ff0\u64cd\u4f5c\u7684\u524d\u63d0\u4e0b\uff0c\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u548c\u6700\u5927\u53ef\u4ee5\u53d8\u4e3a\u591a\u5c11\u3002\u7279\u522b\u5730\uff0c\u7a7a\u6570\u7ec4\u7684\u603b\u548c\u89c6\u4e3a 0\u3002<\/li>\n<\/ul>\n<h2>\u601d\u8def<\/h2>\n<ul>\n<li><span style=\"color: #008000;\">\u601d\u7ef4\u9898\uff0c\u5220\u9664\u64cd\u4f5c\u53ef\u6709\u65e0\u6570\u6b21\uff0c\u4f7f\u5f97\u5143\u7d20\u548c\u6700\u5927\u3002\u5373\u4fdd\u8bc1\u6240\u6709\u7684\u5143\u7d20\u90fd\u4e3a\u975e\u8d1f\u6570\u5373\u53ef\u3002<span style=\"color: #0000ff;\">\u65f6\u95f4\u590d\u6742\u5ea6O(n)\u3002<\/span><\/span><\/li>\n<\/ul>\n<h2>\u4ee3\u7801<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">void solve()\r\n{\r\n   int t;\r\n   cin &gt;&gt; t;\r\n   while (t -- )\r\n   {\r\n        int n , m;\r\n        cin &gt;&gt; n &gt;&gt; m;\r\n        vector&lt;int&gt; a(n + 1);\r\n        for (int i = 1 ; i &lt;= n ; i ++ ) cin &gt;&gt; a[i];\r\n\r\n        int ans = 0;\r\n        for (int i = 1 ; i &lt;= n ; i ++ ) if (a[i] &gt; 0) ans += a[i];\r\n\r\n        cout &lt;&lt; ans &lt;&lt; endl;\r\n   }\r\n\r\n}<\/pre>\n<h1>C.\u5c0f\u82ef\u7684\u6570\u5b57\u6d88\u9664<\/h1>\n<h2>\u9898\u76ee\u63cf\u8ff0<\/h2>\n<ul>\n<li>\u5c0f\u82ef\u6709\u4e00\u4e2a\u957f\u5ea6\u4e3a n\uff0c\u4ec5\u7531\u5b57\u7b26 \u20180\u2019 \u548c \u20181\u2019 \u6784\u6210\u7684\u5b57\u7b26\u4e32 s\u3002\u4e0b\u6807\u4ece 1 \u5f00\u59cb\u3002<br \/>\n\u5c0f\u82ef\u8ba4\u4e3a s \u7684\u957f\u5ea6\u8fc7\u957f\uff0c\u4ed6\u5e0c\u671b\u7528\u4e00\u4e9b\u201c\u6d88\u9664\u201d\u64cd\u4f5c\uff0c\u5c06 s \u7684\u957f\u5ea6\u53d8\u5f97\u5c3d\u53ef\u80fd\u77ed\u3002\u4e00\u6b21\u201c\u6d88\u9664\u201d\u64cd\u4f5c\u63cf\u8ff0\u4e3a\uff1a<br \/>\n\u5982\u679c\u5b58\u5728\u8fd9\u6837\u7684 i (1 \u2264 i &lt; |s|) \u6ee1\u8db3 s_i = s_{i+1}\uff0c\u90a3\u4e48\u5c0f\u82ef\u53ef\u4ee5\u5c06 s_i, s_{i+1} \u8fd9\u4e24\u4e2a\u5b57\u7b26\u6d88\u9664\uff0c\u5176\u4f59\u7684\u5b57\u7b26\u6309\u539f\u6709\u987a\u5e8f\u62fc\u63a5\u8d77\u6765\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u4e00\u6b21\u64cd\u4f5c\u8fc7\u540e\u7684\u5b57\u7b26\u4e32\u53d8\u4e3a s = \"s_1 s_2 ... s_{i-1} s_{i+2} ... s_{|s|}\"\uff08\u5176\u4e2d\uff0c|s| \u7528\u4e8e\u8868\u793a\u5b57\u7b26\u4e32 s \u7684\u957f\u5ea6\uff09\u3002<br \/>\n\u5c0f\u82ef\u4e3a\u4e86\u6700\u5c0f\u5316 s \u7684\u957f\u5ea6\uff0c\u56e0\u6b64\u5728\u5f00\u59cb\u201c\u6d88\u9664\u201d\u64cd\u4f5c\u4e4b\u524d\uff0c\u4ed6\u53ef\u4ee5\u8fdb\u884c\u4e00\u4e9b\u201c\u4fee\u6539\u201d\u64cd\u4f5c\u3002\u4e00\u6b21\u201c\u4fee\u6539\u201d\u64cd\u4f5c\u63cf\u8ff0\u4e3a\uff1a<br \/>\n\u9009\u62e9\u4efb\u610f\u4e00\u4e2a\u4f4d\u7f6e\u4e0a\u7684\u5b57\u7b26\uff0c\u5c06\u5176\u6539\u4e3a \u20180\u2019 \u6216 \u20181\u2019 \u4e2d\u7684\u4efb\u610f\u4e00\u79cd\u3002<br \/>\n\u73b0\u5728\uff0c\u5c0f\u82ef\u60f3\u77e5\u9053\uff0c\u4ed6\u81f3\u5c11\u9700\u8981\u5148\u8fdb\u884c\u51e0\u6b21\u201c\u4fee\u6539\u201d\u64cd\u4f5c\uff0c\u624d\u80fd\u4f7f\u5f97\u5b58\u5728\u8fd9\u6837\u4e00\u79cd\u201c\u6d88\u9664\u201d\u64cd\u4f5c\u7684\u6267\u884c\u65b9\u6848\uff0c\u4f7f\u5f97 s \u7684\u957f\u5ea6\u4e0d\u8d85\u8fc7 1\u3002\u8bf7\u4f60\u5e2e\u4ed6\u7b97\u4e00\u7b97\u5427\u3002<\/li>\n<\/ul>\n<h2>\u601d\u8def<\/h2>\n<ul>\n<li><span style=\"color: #008000;\">\u8d2a\u5fc3\u3002\u4f7f\u7528\u6808\u5148\u8fdb\u540e\u51fa\u7684\u7279\u70b9\uff0c\u5c06\u524d\u9762\u7684\u6570\u5b57\u5b58\u5165\uff0c\u9047\u5230\u76f8\u540c\u7684\u6570\u5b57\u5219\u9000\u6808\uff0c\u5426\u5219\u5165\u6808\u3002\u6700\u540e\u4f1a\u5f97\u5230\u7c7b\u4f3c01010101\u7684\u4e32\uff0c\u5219\u64cd\u4f5c\u6b21\u6570\u4e3aarr.size() \/ 2\u3002<span style=\"color: #0000ff;\">\u65f6\u95f4\u590d\u6742\u5ea6O(n)\u3002<\/span><\/span><\/li>\n<\/ul>\n<h2>\u4ee3\u7801<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">void solve()\r\n{\r\n    int t;\r\n    cin &gt;&gt; t;\r\n    while (t -- ) \r\n    {\r\n        int n;\r\n        cin &gt;&gt; n;\r\n        string s;\r\n        cin &gt;&gt; s;\r\n        s = \" \" + s;\r\n        stack&lt;char&gt; stc;\r\n        \r\n        for (int i = 1 ; i &lt;= n ; i ++ )\r\n        {\r\n            if (stc.size() &amp;&amp; stc.top() == s[i])\r\n                stc.pop();\r\n            else stc.push(s[i]);\r\n        }\r\n        cout &lt;&lt; stc.size() \/ 2 &lt;&lt; endl;\r\n    }\r\n}<\/pre>\n<h1>D.\u5c0f\u82ef\u7684\u6570\u5b57\u96c6\u5408<\/h1>\n<h2>\u9898\u76ee\u63cf\u8ff0<\/h2>\n<ul>\n<li>\u5c0f\u82ef\u6709\u4e00\u4e2a\u53ef\u91cd\u7684\u6570\u5b57\u96c6\u5408 N\uff0c\u521d\u59cb\u65f6\uff0c\u96c6\u5408\u4e2d\u6070\u597d\u6709\u4e24\u4e2a\u6b63\u6574\u6570 x \u548c y\u3002<br \/>\n\u73b0\u5728\uff0c\u5c0f\u82ef\u53ef\u4ee5\u6267\u884c\u82e5\u5e72\u8f6e\u64cd\u4f5c\uff0c\u6bcf\u4e00\u8f6e\u64cd\u4f5c\u4ed6\u90fd\u4f1a\u4ece N \u4e2d\u9009\u62e9\u4e00\u4e2a\u6570\u5b57 a \u548c\u53e6\u4e00\u4e2a\u6570\u5b57 b\uff0c\u5e76\u4ece\u4e0b\u8ff0\u56db\u79cd\u4e2d\u9009\u62e9\u4e00\u79cd\u8fdb\u884c\uff1a<br \/>\n\u2219 \u5c06 a \u4e0e b \u8fdb\u884c\u4f4d\u4e0e\u8fd0\u7b97\uff08and\uff09\u7684\u7ed3\u679c\u52a0\u5165\u96c6\u5408\u3002<br \/>\n\u2219 \u5c06 a \u4e0e b \u8fdb\u884c\u4f4d\u6216\u8fd0\u7b97\uff08or\uff09\u7684\u7ed3\u679c\u52a0\u5165\u96c6\u5408\u3002<br \/>\n\u2219 \u5c06 a \u4e0e b \u8fdb\u884c\u4f4d\u5f02\u6216\u8fd0\u7b97\uff08xor\uff09\u7684\u7ed3\u679c\u52a0\u5165\u96c6\u5408\u3002<br \/>\n\u2219 \u5c06 a \u4e0e b \u7684\u6700\u5927\u516c\u7ea6\u6570\uff08gcd\uff09\u52a0\u5165\u96c6\u5408\u3002<br \/>\n\u5c0f\u82ef\u60f3\u77e5\u9053\uff0c\u6700\u5c11\u9700\u8981\u7ecf\u8fc7\u591a\u5c11\u8f6e\u64cd\u4f5c\uff0c\u624d\u80fd\u4f7f\u5f97\u81ea\u5df1\u7684\u6570\u5b57\u96c6\u5408\u4e2d\u51fa\u73b0\u6570\u5b57 0\uff0c\u8bf7\u4f60\u5e2e\u4ed6\u7b97\u4e00\u7b97\u5427\u3002<br \/>\n\u5982\u679c\u60a8\u9700\u8981\u66f4\u591a\u4f4d\u8fd0\u7b97\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u53ef\u4ee5\u53c2\u8003 OI-Wiki \u7684\u76f8\u5173\u7ae0\u8282\u3002\u76f8\u5173\u94fe\u63a5\uff1a<a href=\"https:\/\/oi-wiki.org\/math\/bit\/#%E4%B8%8E%E6%88%96%E5%BC%82%E6%88%96\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/oi-wiki.org\/math\/bit\/#%E4%B8%8E%E6%88%96%E5%BC%82%E6%88%96<\/a><br \/>\n\u6700\u5927\u516c\u7ea6\u6570\uff0c\u6307\u4e24\u4e2a\u6574\u6570\u5171\u6709\u7ea6\u6570\u4e2d\u6700\u5927\u7684\u4e00\u4e2a\u3002\u4f8b\u5982\uff0c12 \u548c 30 \u7684\u516c\u7ea6\u6570\u6709 1, 2, 3, 6\uff0c\u5176\u4e2d\u6700\u5927\u7684\u7ea6\u6570\u662f 6\uff0c\u56e0\u6b64 gcd(12, 30) = 6\u3002<\/li>\n<\/ul>\n<h2>\u601d\u8def<\/h2>\n<ul>\n<li><span style=\"color: #008000;\">(bfs\u66b4\u529b)\u53ef\u4ee5\u8bc1\u660e\u7b54\u6848\u4e0d\u4f1a\u8d85\u8fc73\u3002\u56e0\u4e3a\u662f\u53ef\u91cd\u96c6\u5408\uff0c\u6bcf\u6b21\u64cd\u4f5c\u540e\u90fd\u4f1a\u52a0\u5165\u96c6\u5408\u5f53\u524d\u64cd\u4f5c\u540e\u7684\u5143\u7d20\uff0c\u7531 a ^ b ^ b = a \u53ef\u77e5 \u6700\u5c11\u4e24\u6b21\u64cd\u4f5c\u4e4b\u540e\u4f1a\u51fa\u73b0\u76f8\u540c\u7684\u6570\u5b57\uff0c\u800c a ^ a = 0\u3002\u6240\u4ee5\u53ef\u77e5\u6700\u591a\u4e09\u6b21\u64cd\u4f5c\u4e4b\u540e\u5c31\u53ef\u4ee5\u5f97\u52300\u3002<span style=\"color: #0000ff;\">\u65f6\u95f4\u590d\u6742\u5ea6O(n\u00b2)\u3002<\/span><\/span><\/li>\n<\/ul>\n<h2>\u4ee3\u7801<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">void solve()\r\n{\r\n    int t;\r\n    cin &gt;&gt; t;\r\n    while (t -- )\r\n    {\r\n        int x , y;\r\n        cin &gt;&gt; x &gt;&gt; y;\r\n        queue&lt;pair&lt;pair&lt;int , int&gt; , int&gt; &gt; q;\r\n        q.push({{x , y} , 0});\r\n        vector&lt;int&gt; vec{x , y};\r\n        while (q.size())\r\n        {\r\n            auto &amp;[a , cnt] = q.front();\r\n            q.pop();\r\n            \r\n            x = a.first , y = a.second;\r\n            \r\n            if (!(x ^ y) || !(x &amp; y) || !(x | y))\r\n            {\r\n                cout &lt;&lt; cnt + 1 &lt;&lt; endl;\r\n                break;\r\n            }\r\n            \r\n            int g = gcd(x , y);\r\n            int arr[4] = {x ^ y , x &amp; y , x | y , g};\r\n                \r\n            for (auto i : vec)\r\n                for (auto j : arr)\r\n                    q.push({{i , j} , cnt + 1});\r\n            for (auto i : arr)\r\n                vec.push_back(i);\r\n        }\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf4\u660e \u6b64\u6587\u7ae0\u4ec5\u4f5c\u8005\u4e2a\u4eba\u89c1\u89e3\u3002\u539f\u9898\u94fe\u63a5https:\/\/ac.nowcoder.com\/acm\/contest\/104637 A.\u5c0f\u82ef &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[23],"tags":[25,35],"class_list":["post-207","post","type-post","status-publish","format-standard","hentry","category-23","tag-25","tag-35"],"_links":{"self":[{"href":"https:\/\/m.qzcy2.top\/index.php\/wp-json\/wp\/v2\/posts\/207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/m.qzcy2.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/m.qzcy2.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/m.qzcy2.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/m.qzcy2.top\/index.php\/wp-json\/wp\/v2\/comments?post=207"}],"version-history":[{"count":4,"href":"https:\/\/m.qzcy2.top\/index.php\/wp-json\/wp\/v2\/posts\/207\/revisions"}],"predecessor-version":[{"id":242,"href":"https:\/\/m.qzcy2.top\/index.php\/wp-json\/wp\/v2\/posts\/207\/revisions\/242"}],"wp:attachment":[{"href":"https:\/\/m.qzcy2.top\/index.php\/wp-json\/wp\/v2\/media?parent=207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/m.qzcy2.top\/index.php\/wp-json\/wp\/v2\/categories?post=207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/m.qzcy2.top\/index.php\/wp-json\/wp\/v2\/tags?post=207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}