{"id":1319,"date":"2024-12-29T09:00:00","date_gmt":"2024-12-29T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1319"},"modified":"2024-12-19T11:23:04","modified_gmt":"2024-12-19T03:23:04","slug":"zerojudge-e465","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-e465\/","title":{"rendered":"ZeroJudge E465: Locker Allocation"},"content":{"rendered":"\n\n\n<p>\u4f60\u662f\u500b\u6ac3\u5b50\u79df\u501f\u5546\uff0c\u7e3d\u5171\u64c1\u6709 M \u500b\u6ac3\u5b50\u3002<br>\u73fe\u5728\u9019 M \u500b\u6ac3\u5b50\u5206\u5225\u88ab N \u500b\u4eba\u501f\u7528\uff0c\u501f\u7528\u91cf\u5206\u5225\u70ba (x0, x1, x2, \u2026xN-1) \u500b\u6ac3\u5b50\uff0c<br>\u5176\u4e2d x0 + x1 + x2 + \u2026 + xN-1 \u2264 M<\/p>\n\n\n\n<p>\u73fe\u5728\u4f60\u60f3\u8981\u4f7f\u7528 S \u500b\u7a7a\u6ac3\u5b50\uff0c<br>\u5728\u88ab\u501f\u7528\u7684\u6ac3\u5b50\u53ea\u80fd\u5920 \u5168\u9000 \u6216 \u5168\u4e0d\u9000\u4e4b\u4e0b\uff0c\u6700\u5c11\u9700\u8981\u8acb\u9019 N \u500b\u4eba\u9000\u9084\u591a\u5c11\u6ac3\u5b50\uff1f<br>\u4e5f\u5c31\u662f\u7576\u6709\u4e00\u500b\u4eba\u501f\u7528 10 \u500b\u6ac3\u5b50\u6642\uff0c\u4e0d\u80fd\u5920\u53ea\u8acb\u4ed6\u9000\u9084 5 \u500b\u6ac3\u5b50\u3002<\/p>\n\n\n\n<p>\u8209\u4f8b\u4f86\u8aaa\uff0c\u5c0d\u65bc M = 20 \u500b\u6ac3\u5b50\uff0c<br>\u73fe\u5728\u5206\u5225\u88ab 5 \u500b\u4eba\u501f\u7528 (1, 7, 2, 8, 2) \u500b\u6ac3\u5b50\uff0c<\/p>\n\n\n\n<p>\u5728\u9700\u8981\u4f7f\u7528 S = 14 \u500b\u6ac3\u5b50\u4e4b\u4e0b\uff0c<br>\u6700\u5c11\u9700\u8981\u8acb\u4ed6\u5011\u9000\u9084 7 + 8 = 15 \u500b\u6ac3\u5b50\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>\u7b2c\u4e00\u884c\u6709\u4e09\u500b\u6b63\u6574\u6578 M\u3001S\u3001N\uff0c<br>\u5206\u5225\u4ee3\u8868\u6ac3\u5b50\u7e3d\u6578 M \u3001 \u60f3\u8981\u4f7f\u7528\u7684\u6ac3\u5b50\u6578 S \u3001 \u501f\u7528\u4eba\u6578 N\u3002<br>M \u2264 100,000<br>S \u2264 M<br>N \u2264 100,000<br>\u7b2c\u4e8c\u884c\u6709 N \u500b\u975e\u8ca0\u6574\u6578 x0, x1, x2, \u2026xN-1\uff0c<br>\u4ee3\u8868\u6bcf\u500b\u4eba\u6240\u501f\u7528\u7684\u6ac3\u5b50\u6578\u91cf\u3002<br>\u5176\u4e2d x0 + x1 + x2 + \u2026 + xN-1 \u2264 M<\/td><td>\u6700\u5c11\u9700\u8981\u8acb\u9019 N \u500b\u4eba\u9000\u9084\u7684\u6ac3\u5b50\u7e3d\u6578<\/td><\/tr><tr><td>20 14 5<br>1 7 2 8 2<\/td><td>15<\/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 01 \u80cc\u5305\u7684\u6982\u5ff5\u4f86\u8655\u7406\u8cc7\u6599\uff0c\u9700\u8981\u5148\u78ba\u8a8d\u9084\u9700\u8981\u9a30\u51fa\u591a\u5c11\u7a7a\u9593\u4f86\uff0c\u6703\u6709\u4e0d\u9700\u8981\u9a30\u7a7a\u9593\u76f4\u63a5\u8f38\u51fa 0 \u7684\u60c5\u6cc1\u3002\u7b54\u6848\u5c31\u662f >= S \u4e4b\u5f8c\u7b2c\u4e00\u500b\u6709\u89e3\u7684\u6578\u5b57\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=e465\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge E465: \u7f6e\u7269\u6ac3\u5206\u914d<\/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;map&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int M, S, N, cabinet[100000] = {}, sum = 0;\n    cin &gt;&gt; M &gt;&gt; S &gt;&gt; N;\n    for (int i = 0; i &lt; N; i++) {\n        cin &gt;&gt; cabinet[i];\n        sum += cabinet[i];\n    }\n    const int target = S - (M - sum);\n    if (target &lt;= 0) cout &lt;&lt; &quot;0\\n&quot;;\n    else {\n        map&lt;int, int&gt;MAP;\n        for (int i = 0; i&lt;N; i++) {\n            const int item = cabinet[i];\n            for (int j = target; j&gt;=0; j--) {\n                if (MAP[j] &gt; 0) {\n                    MAP[j + item]++;\n                }\n            }\n            MAP[item]++;\n        }\n        for (auto it:MAP) {\n            if (it.first &gt;= target && it.second &gt; 0) {\n                cout &lt;&lt; it.first &lt;&lt; &quot;\\n&quot;;\n                break;\n            }\n        }\n    }\n}\n\n\/\/ZeroJudge E465\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4f60\u662f\u500b\u6ac3\u5b50\u79df\u501f\u5546\uff0c\u7e3d\u5171\u64c1\u6709 M \u500b\u6ac3\u5b50\u3002\u73fe\u5728\u9019 M \u500b\u6ac3\u5b50\u5206\u5225\u88ab N \u500b\u4eba\u501f\u7528\uff0c\u501f\u7528\u91cf\u5206\u5225\u70ba (x0, x1, [&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":[6],"tags":[14,20,8,9],"class_list":["post-1319","post","type-post","status-publish","format-standard","hentry","category-6","tag-map","tag-20","tag-8","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1319","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=1319"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1319\/revisions"}],"predecessor-version":[{"id":1321,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1319\/revisions\/1321"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}