{"id":471,"date":"2024-05-10T09:00:00","date_gmt":"2024-05-10T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=471"},"modified":"2024-05-03T23:13:21","modified_gmt":"2024-05-03T15:13:21","slug":"zerojudge-e839","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-e839\/","title":{"rendered":"ZeroJudge E839: \u98f2\u98df\u5206\u985e (Food)"},"content":{"rendered":"\n\n\n<p class=\"\">\u5c0f\u80d6\u611b\u6311\u98df\uff0c\u55dc\u5403\u9ad8\u71b1\u91cf\u7684\u98df\u7269\uff0c\u5c0e\u81f4\u4ed6\u53ea\u9577\u80d6\u4e0d\u9577\u9ad8\u3002\u5728\u65e5\u5e38\u751f\u6d3b\u4e2d\uff0c\u6211\u5011\u9700\u8981\u5404\u985e\u98df\u7269\u7684\u71df\u990a\u4f86\u7dad\u6301\u8eab\u9ad4\u5065\u5eb7\uff0c\u6240\u4ee5\u9078\u64c7\u98df\u7269\u6642\u8981\u8003\u616e\u5176\u71df\u990a\u50f9\u503c\u53ca\u529f\u80fd\u3002<\/p>\n\n\n\n<p class=\"\">\u6211\u5011\u8981\u70ba\u5c0f\u80d6\u6253\u9020\u4e00\u500b\u5206\u985e\u5404\u7a2e\u98f2\u98df\u7684\u7be9\u9078\u5668\uff0c<strong>\u770b\u770b\u73fe\u6709\u7684\u98df\u7269\u4e2d\uff0c\u80fd\u9078\u64c7\u90a3\u4e9b\u98df\u7269\u4f86\u98df\u7528<\/strong>\uff0c\u624d\u80fd\u5747\u8861\u5730\u88dc\u5145\u71df\u990a\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>\u7b2c\u4e00\u884c\u6709\u4e00\u500b\u6b63\u6574\u6578 N (1 &lt;= N &lt;= 50)\uff0c\u4ee3\u8868\u73fe\u6709\u7684\u98df\u7269\u500b\u6578\u3002\u63a5\u4e0b\u4f86 N \u884c\uff0c\u6bcf\u884c\u5404\u6709\u5169\u500b\u5b57\u4e32 F \u8207 S\uff0c\u5f7c\u6b64\u9593\u4ee5\u7a7a\u767d\u9694\u958b\u3002\u5b57\u4e32 F \u4ee3\u8868\u8a72\u98df\u7269\u540d\u7a31 (\u98df\u7269\u540d\u7a31\u4e0d\u91cd\u8907)\uff0c\u5b57\u4e32 S \u4ee3\u8868\u8a72\u98df\u7269\u7a2e\u985e\u3002\u6700\u5f8c\u4e00\u884c (\u7b2c N + 1 \u884c) \u6709\u4e00\u5b57\u4e32 C\uff0c\u4ee3\u8868\u9019\u6b21\u8981\u641c\u5c0b\u7684\u98df\u7269\u7a2e\u985e\u3002\uff08\u5b57\u4e32 F\u3001S \u548c C \u4e0d\u542b\u7a7a\u683c\uff0c\u4e14\u5b57\u5143\u6578\u5747\u4e0d\u8d85\u904e15\u500b\u5b57\u5143\uff09<\/td><td>\u5c0d\u65bc\u6bcf\u7b46\u6e2c\u8cc7\u6309\u7167\u5b57\u5178\u6392\u5e8f (\u7531\u5c0f\u5230\u5927) \u8f38\u51fa\u5c6c\u65bc\u641c\u5c0b\u7a2e\u985e\u7684\u98df\u7269\u540d\u7a31\u3002<strong>\u82e5\u7121\u8a72\u641c\u5c0b\u7a2e\u985e\u7684\u98df\u7269\u5247\u8f38\u51fa\u300cNo\u300d<\/strong>\u3002<\/td><\/tr><tr><td>2<br>apple  fruit<br>milk  drink<br>grains<\/td><td>No<\/td><\/tr><tr><td>5<br>pork  meat<br>tea  drink<br>fish  meat<br>rice  grains<br>beef  meat<br>meat<\/td><td>beef<br>fish<br>pork<\/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=\"\">\u5ba3\u544a\u4e00\u500b <strong>Map&lt;string, vector&lt;string>><\/strong>\uff0c\u7576\u6536\u5230 F \u548c S \u6642\uff0c\u4f7f\u7528 <strong>Map[S].push_back(F)<\/strong>\u3002<\/p>\n\n\n\n<p class=\"\">\u5982\u679c Map[C].size() \u70ba 0\uff0c\u5247\u4ee3\u8868\u6c92\u6709\u7a2e\u985e\u70ba C \u7684\u98df\u7269\uff0c\u8f38\u51fa\u300cNo\u300d\u3002Else \u7684\u8a71\u5c31\u662f\u5148 <strong>Sort Map[C] \u4e26\u8dd1\u4e00\u500b Map[C] \u7684 For\u8ff4\u5708<\/strong>\uff0c\u8f38\u51fa Map[C] \u4e2d\u7684\u6bcf\u4e00\u500b\u5b57\u4e32\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=e839\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge E839: \u98f2\u98df\u5206\u985e (Food)<\/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;map&gt;\n#include &lt;vector&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N;\n    cin &gt;&gt; N;\n    map&lt;string, vector&lt;string&gt;&gt;MAP;\n    for (int i = 0; i&lt;N; i++)\n    {\n        string a, b;\n        cin &gt;&gt; a &gt;&gt; b;\n        MAP[b].push_back(a);\n    }\n    string target;\n    cin &gt;&gt; target;\n    if (MAP[target].size() == 0) cout &lt;&lt; &quot;No\\n&quot;;\n    else\n    {\n        vector&lt;string&gt;ans = MAP[target];\n        sort(ans.begin(), ans.end());\n        for (int i = 0; i&lt;ans.size(); i++)\n        {\n            cout &lt;&lt; ans[i] &lt;&lt; &quot;\\n&quot;;\n        }\n    }\n}\n\n\/\/ZeroJudge E839\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u80d6\u611b\u6311\u98df\uff0c\u55dc\u5403\u9ad8\u71b1\u91cf\u7684\u98df\u7269\uff0c\u5c0e\u81f4\u4ed6\u53ea\u9577\u80d6\u4e0d\u9577\u9ad8\u3002\u5728\u65e5\u5e38\u751f\u6d3b\u4e2d\uff0c\u6211\u5011\u9700\u8981\u5404\u985e\u98df\u7269\u7684\u71df\u990a\u4f86\u7dad\u6301\u8eab\u9ad4\u5065\u5eb7\uff0c\u6240\u4ee5\u9078\u64c7 [&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":[14,20,11,19,9],"class_list":["post-471","post","type-post","status-publish","format-standard","hentry","category-ioi-apcs","tag-map","tag-20","tag-11","tag-19","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/471","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=471"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/471\/revisions"}],"predecessor-version":[{"id":472,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/471\/revisions\/472"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}