{"id":1289,"date":"2024-01-28T17:25:09","date_gmt":"2024-01-28T09:25:09","guid":{"rendered":"http:\/\/www.forillusion.com\/?p=1289"},"modified":"2025-02-14T11:39:10","modified_gmt":"2025-02-14T03:39:10","slug":"codeforces-round-920-div-3-solution","status":"publish","type":"post","link":"https:\/\/www.forillusion.com\/index.php\/codeforces-round-920-div-3-solution\/","title":{"rendered":"Codeforces Round 920 Div. 3 \u9898\u89e3"},"content":{"rendered":"\n<p><div class=\"has-toc have-toc\"><\/div><\/p>\n\n\n\n<p>\u9898\u76ee\u94fe\u63a5\uff1a<a href=\"https:\/\/codeforces.com\/contest\/1921\" target=\"_blank\"  rel=\"nofollow\" >Codeforces Round 920 (Div. 3)<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A. Square<\/h2>\n\n\n\n<p>\u96be\u5ea6\uff1a800<\/p>\n\n\n\n<p>\u8f93\u5165\u77e9\u5f62\u7684\u56db\u4e2a\u5750\u6807\uff0c\u8ba1\u7b97\u56db\u8fb9\u5f62\u7684\u9762\u79ef\u3002<\/p>\n\n\n\n<p>\u83b7\u53d6\u5230\u8f93\u5165\u5750\u6807\u4e2dx\u548cy\u8f74\u7684\u6700\u5c0f\u503c\u6700\u5927\u503c\uff0c\u76f8\u4e58\u8ba1\u7b97\u9762\u79ef\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int t;\nint a&#91;4]&#91;2],minx,miny,maxx,maxy;\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        F(i,0,3)\n            CI a&#91;i]&#91;0]&gt;&gt;a&#91;i]&#91;1];\n        minx=maxx=a&#91;0]&#91;0];\n        miny=maxy=a&#91;0]&#91;1];\n        F(i,0,3)\n        {\n            minx=min(minx,a&#91;i]&#91;0]);\n            maxx=max(maxx,a&#91;i]&#91;0]);\n            miny=min(miny,a&#91;i]&#91;1]);\n            maxy=max(maxy,a&#91;i]&#91;1]);\n        }\n        CO abs(maxx-minx)*abs(maxy-miny) L;\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">B. Arranging Cats<\/h2>\n\n\n\n<p>\u96be\u5ea6\uff1a800<\/p>\n\n\n\n<p>\u7ed9\u51fa\u4e24\u6bb5\u53ea\u75310\u548c1\u7ec4\u6210\u7684\u5b57\u7b26\u4e32s\u548cn\uff0c\u6bcf\u4e00\u6b65\u53ef\u4ee5\u628a\u4e00\u4e2a1\u53d8\u62100\u3001\u628a0\u53d8\u62101\u3001\u628a\u4e00\u4e2a0\u548c1\u5bf9\u8c03\u3002\u6c42\u51fa\u6700\u5c0f\u591a\u5c11\u6b65\u53ef\u4ee5\u8ba9\u5b57\u7b26\u4e32s\u4e0en\u76f8\u7b49\u3002<\/p>\n\n\n\n<p>\u4e3a\u6c42\u51fa\u6700\u5c0f\u7684\u6b65\u6570\uff0c\u53ef\u4ee5\u5148\u628a\u9700\u89810\u53d8\u62101\u548c\u9700\u89811\u53d8\u62100\u7684\u4e24\u4f4d\u8fdb\u884c\u4ea4\u6362\uff0c\u8fd9\u6837\u4e00\u6b65\u5c31\u53ef\u4ee5\u8ba9\u4e24\u4f4d\u5b57\u7b26\u76f8\u7b49\uff0c\u7b49\u65e0\u6cd5\u4ea4\u6362\u65f6\uff0c\u518d\u4e00\u4f4d\u4e00\u4f4d\u7684\u4fee\u6539\u5b57\u7b26\u4e32\u3002\u6240\u4ee5\u5206\u522b\u8ba1\u7b97\u51fas\u548cn\u4e2d\u4e0d\u76f8\u7b49\u4f4d\u4e2d\u5b57\u7b261\u7684\u4e2a\u6570\uff0c\u6700\u5927\u7684\u4e00\u4e2a\u5373\u4e3a\u6700\u5c0f\u6b65\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int t,n;\nstring s1,s2;\nint main()\n{   \n    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        CI n;\n        CI s1&gt;&gt;s2;\n        int x1=0,x2=0;\n        F(i,0,n-1)\n            if (s1&#91;i]!=s2&#91;i])\n            {\n                if (s1&#91;i]=='1') x1++;\n                else x2++; \n            }\n        if (x1&gt;x2) CO x1 L;\n        else CO x2 L;\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">C. Sending Messages<\/h2>\n\n\n\n<p>\u96be\u5ea6\uff1a900<\/p>\n\n\n\n<p>\u6709n\u4e2a\u77ed\u4fe1\u9700\u8981\u53d1\u9001\uff0c\u6bcf\u4e2a\u77ed\u4fe1\u5728\u7b2c[latex]a_i[\/latex]\u65f6\u523b\u53d1\u9001\uff0c\u624b\u673a\u521d\u59cb\u4e3a\u5f00\u673a\u72b6\u6001\u6709f\u683c\u7535\uff0c\u6bcf\u5355\u4f4d\u65f6\u95f4\u4f1a\u6d88\u8017a\u683c\u7535\uff0c\u5f00\u5173\u673a\u4e00\u6b21\u9700\u8981b\u683c\u7535\uff0c\u5f53\u7535\u91cf\u22640\u65f6\u5c06\u65e0\u6cd5\u53d1\u9001\u77ed\u4fe1\u3002\u6c42\u8fd9n\u4e2a\u77ed\u4fe1\u80fd\u5426\u5168\u90e8\u53d1\u51fa\u53bb\u3002<\/p>\n\n\n\n<p>\u8fdb\u884c\u6a21\u62df\u5373\u53ef\uff0c\u5728\u9700\u8981\u53d1\u77ed\u4fe1\u7684\u65f6\u523b\u624b\u673a\u9700\u8981\u4fdd\u6301\u5f00\u673a\u72b6\u6001\uff0c\u4f46\u5728\u6ca1\u53d1\u77ed\u4fe1\u7684\u7b49\u5f85\u65f6\u523b\u53ef\u4ee5\u9009\u62e9\u5f00\u673a\u7b49\u5f85\u6216\u8005\u5173\u673a\u7b49\u5f85\u3002\u5224\u65ad\u5f00\u673a\u7b49\u5f85\u8fd8\u662f\u5173\u673a\u7b49\u5f85\u6d88\u8017\u7684\u7535\u91cf\u5c11\uff0c\u9009\u62e9\u6700\u5c11\u7684\u5373\u53ef\uff0c\u6700\u540e\u770b\u80fd\u5426\u53d1\u5b8c\u5168\u90e8\u77ed\u4fe1\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int t;\nLL mes,power,use,off;\nLL a&#91;200005];\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        CI mes&gt;&gt;power&gt;&gt;use&gt;&gt;off;\n        F(i,1,mes)\n            CI a&#91;i];\n        int t=0,f=1;\n        F(i,1,mes)\n        {\n            if ((a&#91;i]-a&#91;i-1])*use&lt;=off) power-=(a&#91;i]-a&#91;i-1])*use;\n            else power-=off;\n            if (power&lt;=0) \n            {\n                f=0;\n                break;\n            }\n        }\n        if (f) CO \"YES\" L;\n        else CO \"NO\" L;\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">D. Very Different Array<\/h2>\n\n\n\n<p>\u96be\u5ea6\uff1a1100<\/p>\n\n\n\n<p>\u7ed9\u51fa\u4e24\u4e2a\u6570\u7ec4a,b\uff0c\u957f\u5ea6\u5206\u522b\u4e3an,m\uff0c\u4e14n\u2264m\u3002\u8981\u5728b\u6570\u7ec4\u7684m\u4e2a\u6570\u4e2d\u9009\u51fan\u4e2a\u6570\u5e76\u6392\u5e8f\uff0c\u7136\u540e\u4f9d\u6b21\u4e0ea\u6570\u7ec4\u4e2d\u5bf9\u5e94\u7684\u6570\u76f8\u51cf\uff0c\u4f7f\u5f97\u7edd\u5bf9\u503c\u7684\u548c\u6700\u5927\uff0c\u5373sum(abs(ai-bi))\u6700\u5927\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u4f7f\u4e24\u4e2a\u6570\u7ec4\u6bcf\u4e2a\u5143\u7d20\u5dee\u7684\u7edd\u5bf9\u503c\u6700\u5927\uff0c\u9700\u8981\u5c06\u4e24\u4e2a\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u6570\u4e0e\u6700\u5c0f\u7684\u6570\u76f8\u51cf\u3002\u6240\u4ee5\u9996\u5148\u5148\u5c06\u6570\u7ec4a\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff0c\u5c06\u6570\u7ec4b\u4ece\u5927\u5230\u5c0f\u6392\u5e8f\uff0c\u7136\u540e\u518d\u7ef4\u62a4\u4e00\u4e2a\u6570\u7ec4c\u548c\u6307\u9488k\uff0c\u5c06b\u6570\u7ec4\u4e2d\u7684\u524dk\u4e2a\u5143\u7d20\u4f9d\u6b21\u52a0\u5165\u5230\u6570\u7ec4c\u4e2d\uff0c\u518d\u5c06b\u6570\u7ec4\u7684\u540en-k\u4e2a\u5143\u7d20\u4f9d\u6b21\u52a0\u5165\u5230\u6570\u7ec4c\u4e2d\uff0c\u7136\u540e\u518d\u8ba1\u7b97c\u4e0eb\u5dee\u7684\u7edd\u5bf9\u503c\u3002\u4e0d\u65ad\u79fb\u52a8\u6307\u9488k\uff0c\u4fdd\u5b58\u4e0b\u6700\u5927\u7684\u90a3\u4e2a\u5dee\u7684\u7edd\u5bf9\u503c\u3002<\/p>\n\n\n\n<p>\u8fd9\u6837\u505a\u53ef\u4ee5\u5f97\u5230\u6b63\u786e\u7684\u7ed3\u679c\uff0c\u4f46\u662f\u4f1a\u5bfc\u81f4\u8d85\u65f6\u3002\u89c2\u5bdf\u6570\u7ec4c\u53ef\u4ee5\u53d1\u73b0\uff0c\u6bcf\u6b21\u6307\u9488k\u79fb\u52a8\uff0cc\u4e2d\u90fd\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\u53d1\u751f\u4e86\u6539\u53d8\u3002\u6240\u4ee5\u53ef\u4ee5\u76f4\u63a5\u8bb0\u5f55\u4e0bb\u6570\u7ec4\u7684\u524dn\u4e2a\u5143\u7d20\u4e0ea\u7684\u5dee\u7684\u7edd\u5bf9\u503c\uff0c\u540c\u65f6\u6307\u9488k\u6307\u5411b\u6570\u7ec4\u7684\u7b2cn\u4e2a\u6570\uff0c\u7136\u540e\u6307\u9488k\u4e0d\u65ad\u5411\u5de6\u79fb\u52a8\u76f4\u5230\u6307\u5411\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u540c\u65f6\u4e0d\u65ad\u4ece\u8bb0\u5f55\u4e0b\u7684\u7ed3\u679c\u4e2d\u5220\u53bb\u6307\u9488\u6307\u5411\u5143\u7d20b[k]\u4e0e\u5bf9\u5e94\u5143\u7d20a[k]\u7684\u5dee\uff0c\u518d\u6dfb\u52a0\u4e0a\u5bf9\u5e94\u7684\u5143\u7d20b[k+m-n]\u4e0ea[k]\u7684\u5dee\uff0c\u5e76\u8bb0\u5f55\u6700\u5927\u503c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">LL t,n,m,ans,ma;\nLL a&#91;200005],b&#91;200005];\n\nbool cmp(LL a,LL b)\n{\n    return a&gt;b;\n}\n\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        ans=0;\n        ma=0;\n        CI n&gt;&gt;m;\n        CII(a,1,n)\n        CII(b,1,m)\n        sort(a+1,a+n+1);\n        sort(b+1,b+m+1,cmp);\n\n        F(i,1,n)\n            ans+=abs(b&#91;i]-a&#91;i]);\n        ma=ans;\n\n        FD(i,n,1)\n        {\n            ans-=abs(b&#91;i]-a&#91;i]);\n            ans+=abs(b&#91;i+m-n]-a&#91;i]);\n            ma=max(ma,ans);\n        }\n        CO ma L;\n    }\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">E. Eat the Chip<\/h2>\n\n\n\n<p>\u96be\u5ea6\uff1a1600<\/p>\n\n\n\n<p>\u7ed9\u51fa\u4e00\u4e2a\u68cb\u76d8\u548c\u4e24\u4e2a\u5df2\u7ecf\u653e\u5728\u68cb\u76d8\u4e0a\u7684\u68cb\u5b50a,b\uff0ca\u53ea\u80fd\u5411\u4e0b\uff0c\u6cbf\u5bf9\u89d2\u7ebf\u5de6\u4e0b\u3001\u53f3\u4e0b\u79fb\u52a81\u683c\uff0cb\u53ea\u80fd\u5411\u4e0a\uff0c\u6cbf\u5bf9\u89d2\u7ebf\u5de6\u4e0a\u3001\u53f3\u4e0a\u79fb\u52a81\u683c\u3002a\u5148\u8d70\uff0c\u5982\u679c\u4e00\u4e2a\u68cb\u5b50\u79fb\u52a8\u540e\u76d6\u5728\u4e86\u53e6\u4e00\u68cb\u5b50\u4e0a\uff0c\u5c31\u7b97\u8d62\u3002<\/p>\n\n\n\n<p>\u8fd9\u9898\u6839\u636ea,b\u6240\u5728\u5750\u6807\u5c31\u80fd\u5206\u6790\u51fa\u6700\u7ec8\u8c01\u8d62\u3002\u5982\u679ca\u5728b\u68cb\u5b50\u7684\u4e0b\u65b9\u6216\u8005\u5e73\u884c\uff0c\u90a3\u4e48a\u4e00\u76f4\u5411\u4e0b\u8d70\uff0cb\u4e00\u76f4\u5411\u4e0a\u8d70\uff0c\u6700\u540e\u8c01\u90fd\u5403\u4e0d\u4e86\u5bf9\u65b9\uff0c\u6240\u4ee5\u5e73\u624b\u3002\u5982\u679ca\u5728b\u68cb\u5b50\u4e0a\u65b9\uff0c\u4f46\u4e24\u8005\u7684\u6a2a\u5411\u8ddd\u79bb\u592a\u8fdc\uff0c\u76f4\u5230\u4e24\u4e2a\u68cb\u5b50\u5e73\u884c\u6a2a\u5411\u4e0a\u4ecd\u6709\u8ddd\u79bb\uff0c\u5219\u4e3a\u5e73\u624b\u3002<br>\u5982\u679cab\u4e4b\u95f4\u7eb5\u5411\u95f4\u9694\u7684\u683c\u5b50\u4e3a\u5076\u6570\uff0c\u56e0\u4e3aa\u5148\u8d70\uff0c\u6240\u4ee5a\u80fd\u5403\u6389b\uff1b\u540c\u6837\u5982\u679c\u95f4\u9694\u4e3a\u5947\u6570\uff0c\u5219b\u80fd\u5403\u6389a\u3002\u8fd9\u662f\u88ab\u5403\u6389\u7684\u4e00\u65b9\u5c31\u8981\u52aa\u529b\u907f\u5f00\u5bf9\u65b9\u3002\u6240\u4ee5\u8fd8\u9700\u8981\u8ba1\u7b97\u51fa\u5f53\u53cc\u65b9\u5e73\u884c\u65f6\uff0c\u53cc\u65b9\u7684\u6a2a\u5411\u79fb\u52a8\u8303\u56f4\u3002\u5982\u679c\u88ab\u5403\u7684\u4e00\u65b9\u79fb\u52a8\u8303\u56f4\u6709\u4e00\u8fb9\u8d85\u51fa\u4e86\u5403\u7684\u4e00\u65b9\uff0c\u5219\u53ef\u4ee5\u9003\u51fa\u53bb\uff0c\u53d8\u4e3a\u5e73\u5c40\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"cpp\">int t,n,m,xa,ya,xb,yb;\nint main()\n{\n    \/\/ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);\n    CI t;\n    while (t--)\n    {\n        CI n&gt;&gt;m&gt;&gt;xa&gt;&gt;ya&gt;&gt;xb&gt;&gt;yb;\n        if (xa&gt;=xb) CO \"Draw\" L;\n        elif (abs(ya-yb)-1&gt;(xb-xa-1)) CO \"Draw\" L;\n        elif ((xa-xb)%2!=0) \n        {\n            int la=max(1,ya-(xb-xa)\/2-1);\n            int ra=min(m,ya+(xb-xa)\/2+1);\n            int lb=max(1,yb-(xb-xa)\/2);\n            int rb=min(m,yb+(xb-xa)\/2);\n            if (la&lt;=lb&amp;&amp;ra&gt;=rb) CO \"Alice\" L;\n            else CO \"Draw\" L;\n        }\n        else \n        {\n            int la=max(1,ya-(xb-xa)\/2);\n            int ra=min(m,ya+(xb-xa)\/2);\n            int lb=max(1,yb-(xb-xa)\/2);\n            int rb=min(m,yb+(xb-xa)\/2);\n            if (lb&lt;=la&amp;&amp;rb&gt;=ra) CO \"Bob\" L;\n            else CO \"Draw\" L;\n        }\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u94fe\u63a5\uff1aCodeforces Round 920 (Div. 3) A. Square \u96be\u5ea6\uff1a800 \u8f93\u5165\u77e9\u5f62\u7684\u56db\u4e2a\u5750\u6807\uff0c\u8ba1\u7b97\u56db &#8230;<\/p>","protected":false},"author":1,"featured_media":1314,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,35],"tags":[40,12,34,22,39],"class_list":["post-1289","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-3","category-35","tag-codeforces","tag-12","tag-34","tag-22","tag-39"],"_links":{"self":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/comments?post=1289"}],"version-history":[{"count":1,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1289\/revisions"}],"predecessor-version":[{"id":1739,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/posts\/1289\/revisions\/1739"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media\/1314"}],"wp:attachment":[{"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/media?parent=1289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/categories?post=1289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.forillusion.com\/index.php\/wp-json\/wp\/v2\/tags?post=1289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}