{"id":595,"date":"2024-06-15T09:00:00","date_gmt":"2024-06-15T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=595"},"modified":"2024-05-18T02:28:30","modified_gmt":"2024-05-17T18:28:30","slug":"zerojudge-f631","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-f631\/","title":{"rendered":"ZeroJudge F631: \u540c\u5b78\u6703"},"content":{"rendered":"\n\n\n<p class=\"\">\u5f9e\u5927\u7406\u9ad8\u4e2d\u7562\u696d\u5f8c\u5df2\u904e\u4e86 20 \u500b\u5e74\u982d\uff0c\u7576\u5e74\u7684\u73ed\u9577\u6a19\u54e5\u4eca\u5e74\u6c7a\u5b9a\u8209\u8fa6\u4e00\u5834\u8001\u540c\u5b78\u9910\u6703\uff0c\u5927\u5bb6\u6709\u6a5f\u6703\u91cd\u65b0\u805a\u805a\uff0c\u66a2\u98f2\u66a2\u804a\u3002<br>\u7e3d\u5171\u4f86\u4e86 N \u4f4d\u540c\u5b78\uff0c\u9910\u98f2\u7e3d\u5171\u4e0a\u4e86 M \u9053\u83dc\uff0c\u6703\u9910\u524d\u5927\u5bb6\u5df2\u4e8b\u5148\u8b1b\u597d\uff0c\u6bcf\u9053\u83dc\u4e0a\u83dc\u6642\u5c31\u7531\u7576\u6642\u5728\u5ea7\u540c\u5b78\u4e2d<br><strong>\u8eab\u4e0a\u6700\u6709\u9322\u7684\u540c\u5b78\u652f\u4ed8\u8a72\u9053\u83dc\u7684\u91d1\u984d\uff0c\u5982\u679c\u6700\u6709\u9322\u7684\u540c\u5b78\u91d1\u984d\u4e0d\u8db3\uff0c\u5247\u4f9d\u6b21\u7531\u4e0b\u4e00\u4f4d\u6709\u9322\u7684\u540c\u5b78\u652f\u4ed8\u4e0d\u8db3\u7684\u6b3e\u9805\u3002<\/strong><br>\u7576\u7136\uff0c<strong>\u5982\u679c\u6240\u6709\u540c\u5b78\u7684\u91d1\u9322\u7e3d\u548c\u4e0d\u8db3\u4ee5\u652f\u4ed8\u6240\u6709\u7684\u83dc\u991a\u8cbb\u7528\uff0c\u5509! \u90a3\u5c31\u5c37\u5c2c\u4e86 !<\/strong><\/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>EOF \u8f38\u5165 (&lt;= 100 \u7b46)\uff0c\u6bcf\u7b46\u6e2c\u8cc7 3 \u884c\uff0c\u7b2c\u4e00\u884c\u6709\u6574\u6578 N \u548c M (1 &lt;= N\u3001M &lt;=1,0000)\uff0c<br>\u7b2c\u4e8c\u884c\u6709 N \u500b\u6574\u6578\uff0c\u4ee3\u8868\u4e00\u958b\u59cb\u6bcf\u4f4d\u540c\u5b78\u8eab\u4e0a\u651c\u5e36\u7684\u91d1\u984d\uff0c\u7b2c\u4e09\u884c\u6709 M \u500b\u6574\u6578\uff0c\u4f9d\u5e8f\u4ee3\u8868\u6bcf\u4e00\u9053\u83dc\u7684\u61c9\u4ed8\u91d1\u984d\u3002<\/td><td>\u6bcf\u7b46\u6e2c\u8cc7\u4e00\u884c\u8f38\u51fa\uff0c\u5169\u500b\u6574\u6578\uff0c<br>\u4ee3\u8868\u4e00\u958b\u59cb\u6700\u6709\u9322\u7684\u540c\u5b78\u7684\u91d1\u984d\u6578\uff0c<br>\u53ca\u6700\u5f8c\u7528\u9910\u5b8c\u7562\u6642\u6700\u6709\u9322\u7684\u540c\u5b78\u7684\u91d1\u984d\u6578\u3002<br>\u5982\u679c\u4e0d\u5920\u652f\u4ed8\u9910\u9ede\u91d1\u984d\u5247\u8f38\u51fa\u300cOh My God\u300d\u3002<\/td><\/tr><tr><td>3 4<br>100 200 300<br>200 200 200 200<br>5 7<br>1500 1500 1000 2000 3000<br>900 600 200 350 1200 400 1000<\/td><td>Oh My God<br>3000 1450<\/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=\"\">\u53ef\u4ee5\u4f7f\u7528 Priority_Queue \u4f86\u5c07\u6bcf\u500b\u4eba\u6301\u6709\u7684\u91d1\u984d\u5b58\u9032\u53bb\uff0c\u5b58\u8cc7\u6599\u6642\u53ef\u4ee5\u4f7f\u7528 .push(\u91d1\u984d)\u3002\u7576\u8981\u53d6\u8cc7\u6599\u6642\uff0c\u53ef\u4ee5\u4f7f\u7528 .top()\uff0c\u5c31\u6703\u56de\u50b3\u76ee\u524d\u6700\u5927\u503c\u3002<\/p>\n\n\n\n<p class=\"\">\u4f7f\u7528 While\u8ff4\u5708\uff0c\u5982\u679c\u76ee\u524d\u6700\u5927\u91d1\u984d\u53ef\u4ee5\u652f\u4ed8\u76ee\u524d\u7684\u83dc\uff0c\u5c31\u5c07\u6700\u5927\u91d1\u984d -= \u83dc\u7684\u50f9\u9322\uff0c\u4e0d\u80fd\u4f7f\u7528 .top() -= \u83dc\u7684\u50f9\u9322\uff0c\u6240\u4ee5\u53ef\u4ee5\u5c07\u4e00\u500b\u8b8a\u6578\u8a2d\u5b9a\u70ba .top()\uff0c\u7136\u5f8c\u5c07\u9019\u500b\u8b8a\u6578 -= \u83dc\u7684\u50f9\u9322\uff0c\u7136\u5f8c\u4f7f\u7528 .pop()\uff0c\u9019\u6a23\u6703\u5c07\u8cc7\u6599\u4e2d\u6700\u5927\u7684\u91d1\u984d\u522a\u9664\uff0c\u4e26\u4e14\u91cd\u65b0 .push(\u525b\u525b\u9032\u884c\u6e1b\u6cd5\u7684\u8b8a\u6578)\u3002\u5982\u679c\u4e0d\u5920\u652f\u4ed8\u91d1\u984d\uff0c\u5247\u7528\u525b\u525b\u7684\u8fa6\u6cd5\uff0c\u53ea\u662f\u9019\u6b21\u5c07\u8b8a\u6578\u6b78\u96f6\uff0c\u4e26\u4e14\u5c07\u76ee\u524d\u83dc\u7684\u50f9\u9322 -= \u6700\u5927\u91d1\u984d\uff0c\u7136\u5f8c\u7e7c\u7e8c\u8dd1 While\u8ff4\u5708\u3002<\/p>\n\n\n\n<p class=\"\">\u53ef\u4ee5\u8a2d\u5b9a\u4e00\u500b\u5e03\u6797\u503c\u5224\u65b7\u662f\u5426\u8981\u8f38\u51fa\u300cOh My God\u300d\uff0c\u5982\u679c\u5df2\u7d93\u5b8c\u86cb\u4e86\u4e4b\u5f8c\u7684 For\u8ff4\u5708\u53ea\u8981\u6536\u5230\u8cc7\u6599\u4e4b\u5f8c\u90fd\u53ef\u4ee5\u76f4\u63a5 Continue\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=f631\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge F631: \u540c\u5b78\u6703<\/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;queue&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N, M;\n    while (cin &gt;&gt; N &gt;&gt; M)\n    {\n        priority_queue&lt;int&gt;num;\n        for (int i = 0; i&lt;N; i++)\n        {\n            int tmp;\n            cin &gt;&gt; tmp;\n            num.push(tmp);\n        }\n        int first = num.top();\n        bool god = false;\n        for (int i = 0; i&lt;M; i++)\n        {\n            int tmp, count = N-1;\n            cin &gt;&gt; tmp;\n            if (god) continue;\n            while (count &gt;= 0)\n            {\n                if (num.top() &gt;= tmp)\n                {\n                    int t = num.top();\n                    t -= tmp;\n                    num.pop();\n                    num.push(t);\n                    tmp = 0;\n                    break;\n                }\n                tmp -= num.top();\n                num.pop();\n                num.push(0);\n                count--;\n            }\n            if (tmp &gt; 0) god = true;\n        }\n        if (god) cout &lt;&lt; &quot;Oh My God\\n&quot;;\n        else cout &lt;&lt; first &lt;&lt; &quot; &quot; &lt;&lt; num.top() &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge F631\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5f9e\u5927\u7406\u9ad8\u4e2d\u7562\u696d\u5f8c\u5df2\u904e\u4e86 20 \u500b\u5e74\u982d\uff0c\u7576\u5e74\u7684\u73ed\u9577\u6a19\u54e5\u4eca\u5e74\u6c7a\u5b9a\u8209\u8fa6\u4e00\u5834\u8001\u540c\u5b78\u9910\u6703\uff0c\u5927\u5bb6\u6709\u6a5f\u6703\u91cd\u65b0\u805a\u805a\uff0c\u66a2\u98f2\u66a2\u804a\u3002 [&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":[37,8,34,9],"class_list":["post-595","post","type-post","status-publish","format-standard","hentry","category-6","tag-queue","tag-8","tag-34","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/595","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=595"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/595\/revisions"}],"predecessor-version":[{"id":597,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/595\/revisions\/597"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}