{"id":239,"date":"2023-05-18T21:13:35","date_gmt":"2023-05-18T13:13:35","guid":{"rendered":"https:\/\/solost.cn\/?p=239"},"modified":"2023-05-18T21:13:35","modified_gmt":"2023-05-18T13:13:35","slug":"360","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=239","title":{"rendered":"Codeforces Round 685 (Div. 2) &#8211; C. String Equality"},"content":{"rendered":"<h2>\u9898\u76ee\u94fe\u63a5<\/h2>\n<p><a href=\"https:\/\/codeforces.com\/problemset\/problem\/1451\/C\">\u94fe\u63a5<\/a><\/p>\n<h2>\u9898\u76ee\u5927\u610f<\/h2>\n<p>\u7ed9\u4f60\u957f\u5ea6\u4e3an\u7684\u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u4f60\u6709\u4e24\u79cd\u64cd\u4f5c\uff0c\u7b2c\u4e00\u4e2a\u64cd\u4f5c\u4f60\u53ef\u4ee5\u4ea4\u6362<code>a[i], a[i + 1]<\/code>\uff0c\u64cd\u4f5c\u4e8c\uff0c\u4f60\u53ef\u4ee5\u5c06\u8fde\u7eed\u7684<code>k<\/code>\u4e2a\u76f8\u540c\u7684\u5b57\u7b26\u81ea\u589e1\uff0c\u4f8b\u5982<code>a-&gt;b, b-&gt;c<\/code>,\u6700\u5927\u5230z<\/p>\n<h2>\u9898\u89e3<\/h2>\n<h3>\u9519\u8bef\u793a\u8303\uff1a<\/h3>\n<p>\u521a\u5f00\u59cb\u60f3\u7684\u662f\u6392\u5e8f\u4e00\u4e0b\uff0c\u7136\u540e\u7528\u53cc\u6307\u9488\u626b\u63cf\uff0c\u5982\u679ca\u63d0\u4f9b\u7684\u5b57\u7b26\u4e32\u4e0d\u591f\u5c31\u4e0d\u884c\uff0c\u7136\u540e\u8fd9\u4e2a\u9519\u8bef\u70b9\u5728\u4e8e\uff0c\u5982\u679cb\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff0c\u5b83\u53ef\u4ee5\u7531a\u7684\u4efb\u4f55\u5b57\u7b26\u8865\u8fc7\u6765\uff0c\u4f46\u662f\u6211\u7684\u5199\u6cd5\u4f1a\u53ea\u7ba1\u6700\u540e\u7684\u60c5\u51b5\u3002<\/p>\n<pre><code class=\"lang-cpp\">void solve()\n{\n    cin &gt;&gt; n &gt;&gt; k;\n    cin &gt;&gt; a &gt;&gt; b;\n    sort(a.begin(), a.end());\n    sort(b.begin(), b.end());\n    for (int i = 0; i &lt; n; i++) {\n        if (a[i] == b[i])\n            continue;\n        if (a[i] &gt; b[i]) {\n            cout &lt;&lt; &quot;No\\n&quot;;\n            return;\n        }\n        int j = i, l = i;\n        while (j &lt; n &amp;&amp; j - i + 1 &lt;= k &amp;&amp; a[j] == a[i]) j++;\n        while (l &lt; n &amp;&amp; l - i + 1 &lt;= k &amp;&amp; b[l] == b[i]) l++;\n        if (j != l || l - i != k) {\n            cout &lt;&lt; &quot;No\\n&quot;;\n            return;\n        }\n        i = l - 1;\n    }\n    cout &lt;&lt; &quot;Yes\\n&quot;;\n}<\/code><\/pre>\n<h3>\u81ea\u5df1\u5199\u7684\u6b63\u89e3<\/h3>\n<p>\u770b\u4e86\u4e0b\u9898\u89e3\uff0c\u9898\u89e3\u8bf4\u8981\u5355\u4e2a\u5b57\u6bcd\u7edf\u8ba1\uff0c\u904d\u5386\u5b57\u6bcd\u5c31\u884c\u3002\u90a3\u4e48\u6211\u4eec\u7edf\u8ba1\u597d\u4e24\u4e2a\u5b57\u7b26\u4e32\u91cc\u9762\u5b57\u7b26\u7684\u4e2a\u6570\uff0cb\u4e32\u4ece\u540e\u5f80\u524d\u627e\uff0c\u5982\u679cb\u4e32\u7684\u67d0\u4e2a\u5b57\u6bcd\u4e0d\u80fd\u88ab\u6d88\u62100\uff0c\u90a3\u4e48\u4ed6\u5c31\u4e0d\u5408\u6cd5\u3002    \u7136\u540e\u5c31\u662f\u6a21\u62df<\/p>\n<pre><code class=\"lang-cpp\">int n, k;\nstring a, b;\n\nvoid solve()\n{\n    cin &gt;&gt; n &gt;&gt; k;\n    cin &gt;&gt; a &gt;&gt; b;\n    map&lt;int, int&gt; v1, v2;\n    for (auto x : a) {\n        v1[x - &#039;a&#039;]++;\n    }\n    for (auto x : b) {\n        v2[x - &#039;a&#039;]++;\n    }\n    for (int i = 25; i &gt;= 0; i--) {\n        if (!v2[i]) continue;\n        for (int j = i; j &gt;= 0; j--) {\n            if(!v1[j]) continue;\n            if (i == j) {\n                int t = min(v1[i], v2[i]);\n                v1[i] -= t;\n                v2[i] -= t;\n                continue;\n            }\n            if (v2[i] &lt; k &amp;&amp; v2[i]) {\/\/\u6ce8\u610fv2[i] == 0\u65f6\u5019\u4e0d\u80fd\u7b97\u4e0d\u5408\u6cd5\u60c5\u51b5\n                cout &lt;&lt; &quot;NO\\n&quot;;\n                return;\n            }\n            int t = min((v2[i] \/ k), (v1[j] \/ k)) * k;\n            v2[i] -= t;\n            v1[j] -= t;\n            if(!v2[i]) break;\n        }\n        if (v2[i]) {\n            cout &lt;&lt; &quot;NO\\n&quot;;\n            return;\n        }\n    }\n    cout &lt;&lt; &quot;YES\\n&quot;;\n}<\/code><\/pre>\n<h3>\u5b98\u65b9\u9898\u89e3<\/h3>\n<p>\u5b98\u65b9\u9898\u89e3\u5c31\u7b80\u5355\u591a\u4e86\uff0c\u7edf\u8ba1\u6bcf\u4e2a\u5b57\u7b26\u51fa\u73b0\u7684\u6b21\u6570\uff0c\u5982\u679c\u5f53\u524da\u80fd\u63d0\u4f9b\u7684\u5b57\u7b26\u4e0d\u591fb\u7684\u90a3\u5c31\u76f4\u63a5\u8f93\u51fa\u4e0d\u5408\u6cd5\uff0c\u6216\u8005\u662f\u5f53\u524d\u7684a\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u5339\u914d\u5b8cb\u4ee5\u540e\uff0c\u5269\u4e0b\u7684\u5b57\u7b26\u4e0d\u80fd\u88abk\u6574\u9664\uff0c\u90a3\u5c31\u6ca1\u529e\u6cd5\u63d0\u4f9b\u7ed9\u4e0b\u4e00\u4e2a\u5b57\u7b26\u7528\uff0c\u4e5f\u662f\u975e\u6cd5\u60c5\u51b5\u3002\u5982\u679c\u5408\u6cd5\u5c31\u7ed9\u4e0b\u4e00\u4e2a\u5b57\u7b26\u4e32\u52a0\u4e0a\u8fd9\u6b21\u6ca1\u7528\u5b8c\u7684\u5b57\u7b26\u6570\u76ee\u3002<\/p>\n<pre><code class=\"lang-cpp\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\n\nint32_t main() {\n    ios::sync_with_stdio(0); cin.tie(0);\n    int t;\n    cin &gt;&gt; t;\n    while(t--) {\n        int i, n, k; string a, b;\n        cin &gt;&gt; n &gt;&gt; k &gt;&gt; a &gt;&gt; b;\n        array&lt;int, 27&gt; have{}, need{};\n        for(auto&amp; c: a)\n            have[c-&#039;a&#039;]++;\n        for(auto&amp; c: b)\n            need[c-&#039;a&#039;]++;\n   \n        bool bad = false;\n        for(i = 0; i &lt; 26; i++) {\n            if(have[i] &lt; need[i] || (have[i] -= need[i]) % k)\n                bad = true;\n            have[i+1] += have[i];\n        }\n        cout &lt;&lt; (bad? &quot;No&quot; : &quot;Yes&quot;) &lt;&lt; &#039;\\n&#039;;\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u94fe\u63a5 \u94fe\u63a5 \u9898\u76ee\u5927\u610f \u7ed9\u4f60\u957f\u5ea6\u4e3an\u7684\u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u4f60\u6709\u4e24\u79cd\u64cd\u4f5c\uff0c\u7b2c\u4e00\u4e2a\u64cd\u4f5c\u4f60\u53ef\u4ee5\u4ea4\u6362a[i], a[i + 1]\uff0c\u64cd\u4f5c\u4e8c\uff0c\u4f60\u53ef\u4ee5\u5c06\u8fde\u7eed\u7684k\u4e2a\u76f8\u540c\u7684\u5b57\u7b26\u81ea\u589e1\uff0c\u4f8b\u5982a-&gt;b, b-&gt;c,\u6700\u5927\u5230z \u9898\u89e3 \u9519\u8bef\u793a\u8303\uff1a \u521a\u5f00\u59cb\u60f3\u7684\u662f\u6392\u5e8f\u4e00\u4e0b\uff0c\u7136\u540e\u7528\u53cc\u6307\u9488\u626b\u63cf\uff0c\u5982\u679ca\u63d0\u4f9b\u7684\u5b57\u7b26\u4e32\u4e0d\u591f\u5c31\u4e0d\u884c\uff0c\u7136\u540e\u8fd9\u4e2a\u9519\u8bef\u70b9\u5728\u4e8e\uff0c\u5982\u679cb\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff0c\u5b83\u53ef\u4ee5\u7531a\u7684\u4efb\u4f55\u5b57\u7b26\u8865\u8fc7\u6765\uff0c\u4f46\u662f\u6211\u7684\u5199\u6cd5\u4f1a\u53ea\u7ba1\u6700\u540e\u7684\u60c5\u51b5\u3002 void solve() { cin &gt;&gt; n &gt;&gt; k; cin &gt;&gt; a &gt;&gt; b; sort(a.begin(), a.end()); sort(b.begin(), b.end()); for (int i = 0; i &lt; n; i++) { if (a[i] == b[i]) continue; if (a[i] &gt; b[i]) { cout &lt;&lt; &quot;No\\n&quot;; return; } int j [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[5,7],"class_list":["post-239","post","type-post","status-publish","format-standard","hentry","category-solution","tag-5","tag-7"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=239"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/239\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}