{"id":1164,"date":"2024-08-30T09:00:00","date_gmt":"2024-08-30T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1164"},"modified":"2024-08-14T07:34:40","modified_gmt":"2024-08-13T23:34:40","slug":"zerojudge-d375","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-d375\/","title":{"rendered":"ZeroJudge D375: Square"},"content":{"rendered":"\n\n\n<h4 class=\"wp-block-heading\">\u540c\u984c\uff1aUVa 10364 &#8211; Square<\/h4>\n\n\n\n<p>\u7d66\u4f60\u4e00\u4e9b\u68cd\u5b50\u7684\u9577\u5ea6\uff0c\u8acb\u4f60\u7b97\u51fa\u9019\u4e9b\u68cd\u5b50\u662f\u5426\u53ef\u4ee5\u9023\u6210\u4e00\u500b\u6b63\u65b9\u5f62 (\u7aef\u9ede\u5c0d\u7aef\u9ede\uff0c\u4e14\u68cd\u5b50\u4e0d\u53ef\u6298\u65b7)\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\"><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\u7684\u7b2c\u4e00\u5217\u6709\u4e00\u500b\u6574\u6578 N\uff0c\u4ee3\u8868\u4ee5\u4e0b\u6709\u5e7e\u7d44\u6e2c\u8a66\u8cc7\u6599\u3002\u6bcf\u7d44\u6e2c\u8a66\u8cc7\u6599\u4e00\u5217\uff0c\u7b2c\u4e00\u500b\u6574\u6578\u70ba M (4 &lt;= M &lt;= 20)\uff0c\u4ee3\u8868\u68cd\u5b50\u7684\u6578\u76ee\uff0c\u63a5\u4e0b\u4f86\u7684 M \u500b\u6574\u6578\u5206\u5225\u4ee3\u8868\u9019 M \u6839\u68cd\u5b50\u7684\u9577\u5ea6\u3002\u6bcf\u652f\u68cd\u5b50\u7684\u9577\u5ea6\u4ecb\u65bc 1 \u5230 10000 \u4e4b\u9593\u3002<\/td><td>\u5c0d\u6bcf\u4e00\u7d44\u6e2c\u8a66\u8cc7\u6599\uff0c\u5982\u679c\u9019\u4e9b\u68cd\u5b50\u53ef\u4ee5\u9023\u6210\u4e00\u500b\u6b63\u65b9\u5f62\uff0c\u8f38\u51fa\u300cyes\u300d\uff0c\u5426\u5247\u8f38\u51fa\u300cno\u300d\u3002<\/td><\/tr><tr><td>5<br>4 1 1 1 1<br>5 10 20 30 40 50<br>8 1 7 2 6 4 4 3 5<br>8 1 7 2 6 4 4 3 9<br>8 1 7 2 6 4 4 3 13<\/td><td>yes<br>no<br>yes<br>yes<br>no<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge D375 \u7bc4\u4f8b\u6e2c\u8cc7<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u56e0\u70ba\u8981\u7528\u4e0a\u6240\u6709\u68cd\u5b50\uff0c\u6240\u4ee5\u5982\u679c\u6240\u6709\u68cd\u5b50\u7684\u7e3d\u548c\u4e0d\u662f 4 \u7684\u500d\u6578\uff0c\u90a3\u5c31\u4e0d\u53ef\u80fd\u8b8a\u6210\u6b63\u65b9\u5f62\uff0c\u6216\u662f\u6700\u9577\u7684\u68cd\u5b50\u5927\u65bc\u7e3d\u548c\u9664\u4ee5 4\uff0c\u9019\u6a23\u4e5f\u4e0d\u80fd\u8b8a\u6210\u6b63\u65b9\u5f62\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528 DFS \u7684\u65b9\u5f0f\u53bb\u5224\u65b7\u6bcf\u4e00\u7a2e\u53ef\u80fd\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=d375\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge D375: Square<\/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;algorithm&gt;\nusing namespace std;\n\nbool ok = false;\nint MAP[50000] = {}, stick[50000] = {}, N;\n\nvoid DFS(const int length, const int finish, const int add, const int start) {\n    if (finish == 3 || ok) {\n        ok = true;\n        return;\n    }\n    if (add == length) {\n        DFS(length, finish+1, 0, 0);\n        return;\n    }\n    for (int i = start; i&lt;N; i++) {\n        if (MAP[i] == 0 && add+stick[i] &lt;= length) {\n            MAP[i] = 1;\n            DFS(length, finish, add+stick[i], i+1);\n            MAP[i] = 0;\n        }\n        else if (stick[i]+add &gt; length) return;\n    }\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int T;\n    cin &gt;&gt; T;\n    for (int i = 0; i&lt;T; i++) {\n        int sum = 0, max = -999;\n        cin &gt;&gt; N;\n        ok = false;\n        for (int j = 0; j&lt;N; j++) {\n            MAP[j] = 0;\n        }\n        for (int j = 0; j&lt;N; j++) {\n            cin &gt;&gt; stick[j];\n            sum += stick[j];\n            if (stick[j] &gt; max) max = stick[j];\n        }\n        if (sum % 4 != 0 || max &gt; sum \/ 4) {\n            cout &lt;&lt; &quot;no\\n&quot;;\n            continue;\n        }\n        sort(stick, stick+N);\n        DFS(sum \/ 4, 0, 0, 0);\n        if (ok) cout &lt;&lt; &quot;yes\\n&quot;;\n        else cout &lt;&lt; &quot;no\\n&quot;;\n\n    }\n}\n\n\/\/ZeroJudge D375\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 10364 &#8211; Square \u7d66\u4f60\u4e00\u4e9b\u68cd\u5b50\u7684\u9577\u5ea6\uff0c\u8acb\u4f60\u7b97\u51fa\u9019\u4e9b\u68cd\u5b50\u662f\u5426\u53ef\u4ee5\u9023\u6210\u4e00\u500b\u6b63 [&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":[18],"tags":[21,20,8,34,19,9],"class_list":["post-1164","post","type-post","status-publish","format-standard","hentry","category-uva","tag-dfs","tag-20","tag-8","tag-34","tag-19","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/comments?post=1164"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1164\/revisions"}],"predecessor-version":[{"id":1165,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/1164\/revisions\/1165"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=1164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=1164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=1164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}