{"id":516,"date":"2024-05-29T09:00:00","date_gmt":"2024-05-29T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=516"},"modified":"2024-05-07T16:48:34","modified_gmt":"2024-05-07T08:48:34","slug":"zerojudge-a218","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-a218\/","title":{"rendered":"ZeroJudge A218: How many times?"},"content":{"rendered":"\n\n\n<p class=\"\">\u6578\u6578\u8ddf\u6392\u5e8f\u5927\u6982\u662f\u6211\u5011\u5f9e\u5169\u4e09\u6b72\u8d77\u5c31\u958b\u59cb\u8a13\u7df4\u7684\u6280\u80fd\uff0c<\/p>\n\n\n\n<p class=\"\">\u73fe\u5728\u8a72\u662f\u4f60\u597d\u597d\u767c\u63ee\u9019\u500b\u6280\u80fd\u7684\u6642\u5019\u4e86\uff01<\/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><strong>EOF<\/strong> \u8f38\u5165\uff0c\u6bcf\u7d44\u6e2c\u8cc7\u7684\u7b2c\u4e00\u884c\u542b\u4e00\u500b\u6574\u6578 N\uff0c1 &lt;= N &lt;= 1000\uff0c\u63a5\u4e0b\u4f86\u6709 N \u500b\u7bc4\u570d\u70ba 0\uff5e9 \u7684\u6574\u6578 A<sub>1<\/sub>\u3001A<sub>2<\/sub>\u3001\u2026\u3001A<sub>N<\/sub>\u3002<\/td><td>\u628a\u8f38\u5165\u7684\u6578\u5b57<strong>\u6309\u7167\u51fa\u73fe\u6b21\u6578\u7531\u591a\u5230\u5c11\u6392\u5e8f<\/strong>\uff0c<br><strong>\u82e5\u6b21\u6578\u76f8\u540c\uff0c\u512a\u5148\u8f38\u51fa\u6578\u503c\u8f03\u5c0f\u7684\u6578\u5b57<\/strong>\u3002<br>\u53c3\u8003\u7bc4\u4f8b\u8f38\u51fa\u3002<\/td><\/tr><tr><td>5<br>1 4 5 1 4<br>10<br>0 0 0 0 9 9 9 2 2 8<\/td><td>1 4 5<br>0 9 2 8<\/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=\"\">\u5148\u5ba3\u544a\u4e00\u500b Map&lt;int, int> \u7d00\u9304\u6bcf\u4e00\u500b\u6578\u5b57\u51fa\u73fe\u7684\u6b21\u6578\u3002<\/p>\n\n\n\n<p class=\"\">\u518d\u4f86\u8dd1 for (auto it:Map) \u4f86\u53d6\u6bcf\u4e00\u500b\u51fa\u73fe\u7684\u6578\u5b57\u8207\u5176\u51fa\u73fe\u6b21\u6578\uff0c\u5ba3\u544a\u4e00\u500b Vector&lt;pair&lt;int, int>> ans \u4f86\u5b58\u53d6\u9019\u5169\u500b\u8cc7\u6599\u3002<strong>\u5c07 it.first\uff0a-1\uff0c\u56e0\u70ba\u4e4b\u5f8c\u8981\u9032\u884c\u6392\u5e8f\u6578\u503c\u8f03\u5c0f\u8981\u5728\u8f03\u5f8c\u9762<\/strong>\uff0c\u9019\u6a23\u5b50\u53ef\u4ee5\u5f9e\u6700\u5f8c\u9762\u9032\u884c\u8f38\u51fa\u3002<strong>\u5c07 it.first \u9084\u6709 it.second \u5c0d\u8abf\u4e4b\u5f8c Push_Back \u5230 ans \u4e2d<\/strong>\u3002\u5b58\u53d6\u5b8c\u6240\u6709\u8cc7\u6599\u5f8c\u9032\u884c\u6392\u5e8f\u3002\u6700\u5f8c\u5f9e ans \u7684<strong>\u6700\u5f8c\u4e00\u500b\u4f4d\u7f6e\u8f38\u51fa\u5230\u7b2c\u96f6\u500b\u4f4d\u7f6e<\/strong>\uff0c<strong>\u8f38\u51fa ans[i].second\uff0a-1<\/strong>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a218\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge A218: \u9023\u7334\u5b50\u90fd\u6703\u7684\u5c0fcase<\/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    while (cin &gt;&gt; N)\n    {\n        map&lt;int, int&gt;MAP;\n        for (int i = 0; i&lt;N; i++)\n        {\n            int tmp;\n            cin &gt;&gt; tmp;\n            MAP[tmp]++;\n        }\n        vector&lt;pair&lt;int, int&gt;&gt;ans;\n        for (auto it:MAP)\n        {\n            pair&lt;int, int&gt;tmp;\n            tmp.first = it.second;\n            tmp.second = it.first * -1;\n            ans.push_back(tmp);\n        }\n        sort(ans.begin(), ans.end());\n        for (int i = int(ans.size())-1; i&gt;=0; i--)\n        {\n            cout &lt;&lt; ans[i].second * -1 &lt;&lt; &quot; &quot;;\n        }\n        cout &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge A218\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6578\u6578\u8ddf\u6392\u5e8f\u5927\u6982\u662f\u6211\u5011\u5f9e\u5169\u4e09\u6b72\u8d77\u5c31\u958b\u59cb\u8a13\u7df4\u7684\u6280\u80fd\uff0c \u73fe\u5728\u8a72\u662f\u4f60\u597d\u597d\u767c\u63ee\u9019\u500b\u6280\u80fd\u7684\u6642\u5019\u4e86\uff01 \u7bc4\u4f8b\u6e2c\u8cc7 \u7bc4\u4f8b\u8f38\u5165 \u7bc4 [&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":[29],"tags":[14,23,20,19,9],"class_list":["post-516","post","type-post","status-publish","format-standard","hentry","category-zerojudge-","tag-map","tag-pair","tag-20","tag-19","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/516","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=516"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/516\/revisions"}],"predecessor-version":[{"id":517,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/516\/revisions\/517"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}