{"id":523,"date":"2024-06-01T09:00:00","date_gmt":"2024-06-01T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=523"},"modified":"2024-05-08T12:10:39","modified_gmt":"2024-05-08T04:10:39","slug":"zerojudge-e541","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-e541\/","title":{"rendered":"ZeroJudge E541: Where is the marble"},"content":{"rendered":"\n\n\n<h4 class=\"wp-block-heading\">\u540c\u984c\uff1aUVa 10474 &#8211; Where is the marble<\/h4>\n\n\n\n<p class=\"\">Raju \u548c Meena \u559c\u6b61\u73a9\u5927\u7406\u77f3 (Marble)\u3002\u4ed6\u5011\u6709\u5f88\u591a\u4e0a\u5beb\u6709\u6578\u5b57\u7684\u5927\u7406\u77f3\u3002<br>\u525b\u958b\u59cb\uff0cRaju \u6703<strong>\u6309\u7167\u66f8\u5beb\u5728\u4e0a\u9762\u7684\u6578\u5b57\u4ee5\u5347\u5e8f\u4f9d\u6b21\u653e\u7f6e\u5927\u7406\u77f3<\/strong>\u3002<br>\u7136\u5f8c\uff0cMeena \u6703\u8981\u6c42 Raju <strong>\u627e\u5230\u6307\u5b9a\u865f\u78bc\u7684\u7b2c\u4e00\u584a\u5927\u7406\u77f3<\/strong>\u3002<br>\u5982\u679c Raju \u6210\u529f\uff0cRaju \u5c07\u7372\u5f97\u4e00\u5206\uff0c\u5982\u679c Raju \u5931\u6557\uff0cMeena \u5c07\u7372\u5f97\u4e00\u5206\u3002<br>\u7d93\u904e\u591a\u6b21\u7684\u8a62\u554f\uff0c\u904a\u6232\u7d50\u675f\uff0c\u7372\u5f97\u6700\u9ad8\u5206\u7684\u73a9\u5bb6\u7372\u52dd\u3002<br>\u4eca\u5929\uff0c\u4f60\u6709\u6a5f\u6703\u5e6b\u52a9 Raju\u3002\u4f46\u662f\u8acb\u4e0d\u8981\u5c0f\u770b Meena\uff0c\u5979\u5beb\u4e86\u4e00\u500b\u7a0b\u5f0f\u4f86\u8ffd\u8e64\u4f60\u82b1\u591a\u5c11\u6642\u9593\u624d\u80fd\u7d66\u51fa\u6240\u6709\u7b54\u6848\u3002<br>\u56e0\u6b64\uff0c\u4f60\u4e5f\u5fc5\u9808\u5beb\u4e86\u4e00\u500b\u6709\u6548\u7387\u7684\u7a0b\u5f0f\uff0c\u4f86\u78ba\u4fdd\u52dd\u5229\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><strong>EOF<\/strong> \u8f38\u5165\uff0c\u6bcf\u7d44\u6e2c\u8cc7\u958b\u982d\u6709\u5169\u500b\u6574\u6578 <strong>N \u548cQ<\/strong>\u3002<br>N \u662f\u5927\u7406\u77f3\u7684\u6578\u91cf\uff0cQ \u662f Meena \u7684\u67e5\u8a62\u6578\u91cf\u3002<br>\u5982\u679c N = Q = 0 \u4ee3\u8868\u8f38\u5165\u7d50\u675f\u3002<br>\u63a5\u4e0b\u4f86 N \u884c\u5305\u542b N \u500b\u5927\u7406\u77f3\u4e0a\u5beb\u7684\u6578\u5b57\u3002\u9019\u4e9b\u5927\u7406\u77f3\u7de8\u865f\u4e0d\u6703\u4ee5\u4efb\u4f55\u7279\u5b9a\u9806\u5e8f\u51fa\u73fe\u3002<br>\u63a5\u4e0b\u4f86\u7684 Q \u884c\u5c07\u9032\u884c Q \u6b21\u67e5\u8a62\u3002<br>\u6240\u6709\u6578\u5b57\u7686 &lt;= 10000\uff0c\u4e26\u4e14\u4e0d\u70ba\u8ca0\u6578\u3002<\/td><td>\u5c0d\u65bc\u6bcf\u7d44\u6e2c\u8cc7\uff0c\u8f38\u51fa\u6e2c\u8cc7\u7de8\u865f\u3002<br>\u5c0d\u65bc\u6bcf\u500b\u67e5\u8a62\uff0c\u5982\u679c\u5728\u4f4d\u7f6ey\u4e0a\u627e\u5230\u7b2c\u4e00\u500b\u7de8\u865f\u70ba x \u7684\u5927\u7406\u77f3<br>\u8f38\u51fa\u300cx found at y\u300d<br>\u5982\u679c\u6c92\u6709\u7de8\u865f\u70ba x \u7684\u5927\u7406\u77f3<br>\u8f38\u51fa\u300cx not found\u300d<\/td><\/tr><tr><td><strong>4 1<\/strong><br>2<br>3<br>5<br>1<br>5<br><strong>5 2<\/strong><br>1<br>3<br>3<br>3<br>1<br>2<br>3<br><strong>0 0<\/strong><\/td><td>CASE# 1:<br>5 found at 4<br>CASE# 2:<br>2 not found<br>3 found at 3<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge E541 \u7bc4\u4f8b\u6e2c\u8cc7<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\">\u5148\u5c07 N \u500b\u77f3\u982d\u7684\u7de8\u865f\u6536\u5230\u4e00\u500b\u9663\u5217\u4e2d\u4e26\u4e14\u6392\u5e8f\uff0c\u518d\u4f86\u5ba3\u544a\u4e00\u500b Map&lt;int, int>\uff0c\u4e26\u4e14\u8dd1 For\u8ff4\u5708\u5f9e 0 \u8dd1\u5230 N-1\uff0c\u5982\u679c Map[\u9663\u5217[i]] \u70ba 0\uff0c\u5247 Map[\u9663\u5217[i]] = i + 1\u3002\u56e0\u70ba\u5982\u679c\u6709\u91cd\u8907\u51fa\u73fe\u7684\u6578\u5b57\u8981\u53d6\u6700\u524d\u9762\u90a3\u500b\u6240\u4ee5\u8981\u5148\u5224\u65b7 Map \u4e2d\u662f\u5426\u5df2\u7d93\u5b58\u5728\u67d0\u6578\u7684\u4f4d\u7f6e\u4e86\u3002<\/p>\n\n\n\n<p class=\"\">\u8f38\u51fa\u6642\u5224\u65b7\u8981\u67e5\u8a62\u7684\u6578\u5b57\u662f\u5426\u5b58\u5728\u65bc Map \u4e2d\uff0c\u5982\u679c Map[\u6578\u5b57] == 0 \u4ee3\u8868\u6c92\u6709\u9019\u500b\u6578\u5b57\u8f38\u51fa\u300cnot found\u300d\uff0c\u5426\u5247\u8f38\u51fa Map[\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=e541\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge E541: Where is the marble<\/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;\n#include &lt;map&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N, Q, count = 1;\n    while (cin &gt;&gt; N &gt;&gt; Q && N != 0 && Q != 0)\n    {\n        vector&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_back(tmp);\n        }\n        sort(num.begin(), num.end());\n        map&lt;int, int&gt;MAP;\n        for (int i = 0; i&lt;N; i++)\n        {\n            if (MAP[num[i]] == 0) MAP[num[i]] = i+1;\n        }\n        cout &lt;&lt; &quot;CASE# &quot; &lt;&lt; count &lt;&lt; &quot;:\\n&quot;;\n        for (int i = 0; i&lt;Q; i++)\n        {\n            int tmp;\n            cin &gt;&gt; tmp;\n            if (MAP[tmp] == 0) cout &lt;&lt; tmp &lt;&lt; &quot; not found\\n&quot;;\n            else cout &lt;&lt; tmp &lt;&lt; &quot; found at &quot; &lt;&lt; MAP[tmp] &lt;&lt; &quot;\\n&quot;;\n        }\n        count++;\n    }\n}\n\n\/\/ZeroJudge E541\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 10474 &#8211; Where is the marble Raju \u548c Meena \u559c [&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":[18],"tags":[14,20,8,19,9],"class_list":["post-523","post","type-post","status-publish","format-standard","hentry","category-uva","tag-map","tag-20","tag-8","tag-19","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/523","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=523"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/523\/revisions"}],"predecessor-version":[{"id":525,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/523\/revisions\/525"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}