{"id":1307,"date":"2024-12-15T09:00:00","date_gmt":"2024-12-15T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1307"},"modified":"2024-12-08T00:15:39","modified_gmt":"2024-12-07T16:15:39","slug":"zerojudge-d559","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-d559\/","title":{"rendered":"ZeroJudge E559: Luggage"},"content":{"rendered":"\n\n\n<h4 class=\"wp-block-heading\">\u540c\u984c\uff1aUVa 10664 &#8211; Luggage<\/h4>\n\n\n\n<p>Peter \u548c\u4ed6\u7684\u670b\u53cb\u5011\u6b63\u5728\u5ea6\u5047\uff0c\u4ed6\u5011\u6c7a\u5b9a\u4e58\u8eca\u53bb\u897f\u73ed\u7259\u7684\u5317\u90e8\u3002<br>\u4ed6\u5011\u7e3d\u5171\u4e03\u500b\u4eba\uff0c\u4ed6\u5011\u8a8d\u70ba\u5169\u8f1b\u6c7d\u8eca\u8db3\u4ee5\u5bb9\u7d0d\u6240\u6709\u4eba\u7684\u884c\u674e\u3002<br>\u6642\u9593\u5230\u5566\uff01\u8a72\u51fa\u767c\u4e86\u3002<br>\u53f8\u6a5f\u5011\u5c0d\u54ea\u500b\u884c\u674e\u7bb1\u5fc5\u9808\u653e\u5165\u54ea\u500b\u5f8c\u8eca\u7bb1\u6301\u4e0d\u540c\u610f\u898b\uff0c\u56e0\u70ba\u6c92\u4eba\u5e0c\u671b\u81ea\u5df1\u7684\u8eca\u8f09\u7684\u884c\u674e\u66f4\u91cd(\u56e0\u70ba\u8017\u6cb9)\u3002<br>\u8981\u5982\u4f55\u624d\u80fd\u8b93\u5169\u8f1b\u6c7d\u8eca\u8f09\u7684\u884c\u674e\u91cd\u91cf\u76f8\u540c\uff1f(\u53f8\u6a5f\u4e0d\u80fd\u628a\u884c\u674e\u62c6\u958b\u6216\u8005\u5206\u88dd\uff01\uff09<br>\u8003\u616e\u6bcf\u500b\u884c\u674e\u7bb1\u5916\u90fd\u6709\u4e00\u500b\u6a19\u7c64 M \u4ee3\u8868\u8a72\u884c\u674e\u91cd\u91cf\u3002<br>\u5982\u679c\u53ef\u80fd\u7684\u8a71\uff0c\u8acb\u4f60\u5e6b\u500b\u5fd9\uff0c\u8b93\u5169\u8f1b\u6c7d\u8eca\u8f09\u7684\u884c\u674e\u91cd\u91cf\u76f8\u540c\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\u884c\u5305\u542b\u4e00\u500b\u6574\u6578 T\uff0cT \u4ee3\u8868\u6e2c\u8cc7\u6578\u91cf\u3002<br>\u6bcf\u7d44\u6e2c\u8cc7\u4e00\u884c\uff0c\u6b64\u884c\u5305\u542b N \u500b\u6574\u6578 (1 \u2264 N \u2264 20)\u3002<br>\u9019\u4e9b\u6574\u6578\u4ee3\u8868\u6bcf\u500b\u884c\u674e\u7bb1\u7684\u91cd\u91cf M (0 &lt; M \u2264 200)\u3002<\/td><td>\u5c0d\u65bc\u6bcf\u7d44\u6e2c\u8cc7\uff0c\u5982\u679c\u53ef\u4ee5\u8b93\u5169\u8f1b\u6c7d\u8eca\u8f09\u7684\u884c\u674e\u91cd\u91cf\u76f8\u540c\uff0c\u8f38\u51fa\u300cYES\u300d\u3002\u5426\u5247\u8f38\u51fa\u300cNO\u300d\u3002<\/td><\/tr><tr><td>3<br>1 2 1 2 1<br>2 3 4 1 2 5 10 50 3 50<br>3 5 2 7 1 7 5 2 8 9 1 25 15 8 3 1 38 45 8 1<\/td><td>NO<br>YES<br>YES<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u4f7f\u7528\u5b57\u4e32\u6536\u8cc7\u6599\uff0c\u5c07\u5176\u5207\u6210\u6574\u6578\u9663\u5217\uff0c\u4e26\u4e14\u5c07\u6240\u6709\u884c\u674e\u7684\u91cd\u91cf\u52a0\u8d77\u4f86\uff0c\u5982\u679c\u6240\u6709\u91cd\u91cf\u7684\u548c\u70ba\u5947\u6578\u5247\u76f4\u63a5\u8f38\u51fa\u300cNO\u300d\u3002\u53cd\u4e4b\uff0c\u8a08\u7b97\u91cd\u91cf\u7684\u4e00\u534a\uff0c\u9019\u500b\u662f\u6211\u5011\u8981\u6c42\u7684\u6578\u5b57\uff0c\u56e0\u70ba\u53ea\u8981\u53ef\u4ee5\u6c42\u5230\u4e00\u500b\u53e6\u5916\u4e00\u908a\u4e00\u5b9a\u4e5f\u80fd\u6c42\u5230\u76f8\u540c\u7684\u6578\u5b57\u3002<\/p>\n\n\n\n<p>\u5ba3\u544a\u4e00\u500b Map \u4f86\u5b58\u54ea\u4e9b\u6578\u5b57\u6216\u662f\u6578\u5b57\u548c\u51fa\u73fe\u904e\uff0c\u5c07\u9663\u5217\u4e2d\u7684\u6578\u5b57\u4e00\u4e00\u8dd1\u904e\uff0c\u88e1\u9762\u5728\u8dd1\u4e00\u500b\u8ff4\u5708\u5f9e\u4e00\u534a\u8dd1\u5230\u76ee\u524d\u7684\u6578\u5b57\uff0c\u662f &#8211;\u3002\u5982\u679c Map[\u76ee\u524d\u6578\u5b57 &#8211; \u9663\u5217\u6578\u5b57] > 0\uff0c\u5247\u5c07 Map[\u76ee\u524d\u6578\u5b57]++\u3002\u6700\u5f8c\u4e5f\u8981\u5c07 Map[\u9663\u5217\u6578\u5b57]++\u3002<\/p>\n\n\n\n<p>\u5982\u679c Map[\u4e00\u534a] > 0\uff0c\u5c31\u4ee3\u8868\u53ef\u4ee5\u5e73\u5206\uff0c\u53cd\u4e4b\u5c31\u662f\u4e0d\u884c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=e559\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge E559: Luggage<\/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;\n#include &lt;unordered_map&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int T;\n    cin &gt;&gt; T;\n    cin.ignore();\n    for (int i = 0; i&lt;T; i++) {\n        string str;\n        getline(cin, str);\n        string add = &quot;&quot;;\n        vector&lt;int&gt;v;\n        int sum = 0;\n\n        for (int j = 0; j&lt;str.length(); j++) {\n            const char ch = str[j];\n            if (ch == &#39; &#39;) {\n                int toInt;\n                if (add.length() == 1) toInt = add[0] - &#39;0&#39;;\n                else toInt = stoi(add);\n                sum += toInt;\n                v.push_back(toInt);\n                add = &quot;&quot;;\n                continue;\n            }\n            add += ch;\n        }\n        if (add.length() &gt; 0) {\n            int tmp;\n            if (add.length() == 1) tmp = add[0] - &#39;0&#39;;\n            else tmp = stoi(add);\n            sum += tmp;\n            v.push_back(tmp);\n        }\n        if (sum % 2 != 0) cout &lt;&lt; &quot;NO\\n&quot;;\n        else {\n            const int half = sum \/ 2;\n            unordered_map&lt;int, int&gt;MAP;\n            for (int i = 0; i&lt;v.size(); i++) {\n                const int tmp = v[i];\n                for (int j = half; j&gt;=tmp; j--) {\n                    if (MAP[j-tmp] &gt; 0) MAP[j]++;\n                }\n                MAP[tmp]++;\n            }\n            if (MAP[half] &gt; 0) cout &lt;&lt; &quot;YES\\n&quot;;\n            else cout &lt;&lt; &quot;NO\\n&quot;;\n        }\n    }\n}\n\n\/\/ZeroJudge E559\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 10664 &#8211; Luggage Peter \u548c\u4ed6\u7684\u670b\u53cb\u5011\u6b63\u5728\u5ea6\u5047\uff0c\u4ed6\u5011\u6c7a\u5b9a\u4e58\u8eca\u53bb\u897f\u73ed [&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":[14,20,8,11,9],"class_list":["post-1307","post","type-post","status-publish","format-standard","hentry","category-uva","tag-map","tag-20","tag-8","tag-11","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1307","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=1307"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1307\/revisions"}],"predecessor-version":[{"id":1309,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1307\/revisions\/1309"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}