{"id":409,"date":"2024-04-30T15:37:00","date_gmt":"2024-04-30T07:37:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=409"},"modified":"2024-04-30T15:37:02","modified_gmt":"2024-04-30T07:37:02","slug":"zerojudge-j537","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-j537\/","title":{"rendered":"ZeroJudge J537: \u5de5\u5ee0\u6d3e\u9063 (Factory)"},"content":{"rendered":"\n\n\n<p class=\"\">\u6709\u9593\u4f01\u696d\u6700\u8fd1\u65b0\u958b\u4e86 N \u9593\u5de5\u5ee0\uff0c\u6253\u7b97\u5c07\u54e1\u5de5\u6d3e\u9063\u81f3\u5404\u5de5\u5ee0\u5de5\u4f5c\u3002\u5404\u5de5\u5ee0\u6709\u9810\u4f30\u7684\u71df\u6536\u503c A<sub>i<\/sub> \u548c\u54e1\u5de5\u9700\u6c42\u4eba\u6578 P\u3002i \u4f01\u696d\u4e3b<strong>\u5c07\u4f9d\u64da\u5de5\u5ee0\u7684\u71df\u6536\u503c\u7531\u9ad8\u5230\u4f4e\u4f86\u5206\u914d\u54e1\u5de5<\/strong>\uff0c<strong>\u82e5\u71df\u6536\u503c\u8f03\u9ad8\u7684\u5de5\u5ee0\u5df2\u6eff\u8db3\u54e1\u5de5\u9700\u6c42\u4eba\u6578\uff0c\u624d\u6703\u5c07\u54e1\u5de5\u5206\u914d\u7d66\u71df\u6536\u503c\u8f03\u4f4e\u7684\u5de5\u5ee0<\/strong>\uff0c<strong>\u76f4\u5230\u6240\u6709\u54e1\u5de5\u90fd\u5df2\u5206\u914d\u5b8c\u6210\u6216\u8005\u6240\u6709\u5de5\u5ee0\u7684\u9700\u6c42\u90fd\u5df2\u6eff\u8db3\u70ba\u6b62<\/strong>\u3002<\/p>\n\n\n\n<p class=\"\">\u5047\u8a2d\u4e0d\u6703\u6709\u4efb\u5169\u9593\u5de5\u5ee0\u7684\u9810\u4f30\u71df\u6536\u503c\u76f8\u540c\u3002\u7d66\u5b9a\u5404\u5de5\u5ee0\u7684\u8cc7\u8a0a\u4ee5\u53ca\u4f01\u696d\u7684\u7e3d\u54e1\u5de5\u6578\uff0c\u8acb\u4f60\u64b0\u5beb\u7a0b\u5f0f\u8a08\u7b97\u6709\u5e7e\u9593\u5de5\u5ee0\u6709\u54e1\u5de5\u9032\u99d0\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 nfd-wb-animate nfd-wb-fade-in-bottom-short\"><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\u7b2c\u4e00\u5217\u6709\u4e00\u500b\u6574\u6578 N (1 \u2264 N \u2264 350)\uff0c\u4ee3\u8868\u6709\u5e7e\u9593\u5de5\u5ee0\u3002\u63a5\u4e0b\u4f86\u6709 N \u5217\uff0c\u6bcf\u5217\u6709\u5169\u500b\u6574\u6578 A<sub>i<\/sub> (1\u2264 Ai \u2264 6000\uff0ci = 1, 2, 3, \u2026, N) \u548c P<sub>i<\/sub>  (1 \u2264 Pi \u2264 3000\uff0ci = 1, 2, 3, \u2026, N)\uff0c\u4ee3\u8868\u7684\u662f\u7b2c i \u9593\u5de5\u5ee0\u7684\u9810\u4f30\u71df\u6536\u503c\u53ca\u54e1\u5de5\u9700\u6c42\u4eba\u6578\u3002<br>\u6700\u5f8c\u4e00\u5217\u6709\u4e00\u500b\u6574\u6578 H (0 \u2264 H \u2264 1,050,000)\uff0c\u4ee3\u8868\u7e3d\u54e1\u5de5\u6578\u3002<\/td><td>\u8acb\u6839\u64da\u5de5\u5ee0\u6d3e\u9063\u898f\u5247\uff0c<strong>\u8f38\u51fa\u6709\u5e7e\u9593\u5de5\u5ee0\u6709\u54e1\u5de5\u9032\u99d0<\/strong>\u3002<\/td><\/tr><tr><td>3<br>30  10<br>20  5<br>10  3<br>10<\/td><td>1<\/td><\/tr><tr><td>4<br>2  6<br>3  2<br>5  7<br>8  9<br>18<\/td><td>3<\/td><\/tr><tr><td>6<br>90  5<br>30  6<br>70  8<br>20  4<br>1000  5000<br>500  800<br>5130<\/td><td>2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\">\u4f7f\u7528 <strong>Pair&lt;int, int> \u5c07\u6bcf\u500b\u5de5\u5ee0\u7684\u300c\u9810\u671f\u71df\u6536\u503c\u300d\u548c\u300c\u9700\u8981\u7684\u4eba\u6578\u300d\u5b58\u5728\u4e00\u8d77<\/strong>\uff0c\u4e26\u5c07\u6bcf\u4e00\u500b\u5de5\u5ee0\u7684 <strong>Pair \u5b58\u5230\u9663\u5217\u4e2d\u9032\u884c Sort<\/strong>\uff0c\u6700\u5f8c\u9762\u7684 Pair \u5c31\u6703\u662f\u300c\u9810\u671f\u71df\u6536\u503c\u6700\u5927\u7684\u5de5\u5ee0\u300d\u3002<\/p>\n\n\n\n<p class=\"\">\u4f7f\u7528 <strong>For\u8ff4\u5708 \u5f9e\u6700\u5f8c\u9762\u8dd1\u5230\u6700\u524d\u9762\u7684\u4f4d\u7f6e<\/strong>\uff0c\u6bcf\u4e00\u6b21\u5c07 <strong>H \u6e1b\u6389\u76ee\u524d\u5de5\u5ee0\u300c\u9700\u8981\u7684\u4eba\u6578\u300d<\/strong>\u4e26\u5c07\u7b54\u6848\u8b8a\u6578 +1\u3002\u6bcf\u6b21 For\u8ff4\u5708 \u90fd\u9700\u8981\u5224\u65b7 <strong>H \u662f\u5426\u5c0f\u65bc\u7b49\u65bc 0\uff0c\u5982\u679c\u662f\u7684\u8a71\u5c31\u53ef\u4ee5\u5c07 For \u8ff4\u5708 Break<\/strong>\u6389\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=j537\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge J537: \u5de5\u5ee0\u6d3e\u9063 (Factory)<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right nfd-delay-50\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;vector&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\n\npair&lt;int, int&gt; rtn (int a, int b)\n{\n    pair&lt;int, int&gt;tmp;\n    tmp.first = a;\n    tmp.second = b;\n    return tmp;\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N;\n    cin &gt;&gt; N;\n    vector&lt;pair&lt;int, int&gt;&gt;v;\n    for (int i = 0; i&lt;N; i++)\n    {\n        int a, b;\n        cin &gt;&gt; a &gt;&gt; b;\n        v.push_back(rtn(a, b));\n    }\n    sort(v.begin(), v.end());\n    int count;\n    cin &gt;&gt; count;\n    int ans = 0;\n    for (int i = N-1; i&gt;=0; i--)\n    {\n        if (count &lt;= 0) break;\n        count -= v[i].second;\n        ans++;\n    }\n    cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/ZeroJudge J537\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u9593\u4f01\u696d\u6700\u8fd1\u65b0\u958b\u4e86 N \u9593\u5de5\u5ee0\uff0c\u6253\u7b97\u5c07\u54e1\u5de5\u6d3e\u9063\u81f3\u5404\u5de5\u5ee0\u5de5\u4f5c\u3002\u5404\u5de5\u5ee0\u6709\u9810\u4f30\u7684\u71df\u6536\u503c Ai \u548c\u54e1\u5de5\u9700\u6c42\u4eba\u6578 P\u3002i [&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":[25],"tags":[23,20,8,19,13,9],"class_list":["post-409","post","type-post","status-publish","format-standard","hentry","category-ioi-apcs","tag-pair","tag-20","tag-8","tag-19","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/409","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=409"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/409\/revisions"}],"predecessor-version":[{"id":411,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/409\/revisions\/411"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}