{"id":587,"date":"2024-06-19T09:00:00","date_gmt":"2024-06-19T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=587"},"modified":"2024-05-17T16:25:21","modified_gmt":"2024-05-17T08:25:21","slug":"itsa-202404-2","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/itsa-202404-2\/","title":{"rendered":"ITSA 202404 #2\uff1a\u9ede\u9ede\u540d"},"content":{"rendered":"\n\n\n<p class=\"\">\u67d0\u793e\u5718\u60f3\u73a9\u4e00\u500b\u904a\u6232\uff0c\u6709 N \u500b\u540c\u5b78\u6392\u6210\u4e00\u6392\uff0c\u4e00\u958b\u59cb\u5f9e 1 \u958b\u59cb\u6578\u5230 K\uff0c\u5c07\u7b2c K \u500b\u540c\u5b78\u5c31\u8868\u793aPASS\uff0c\u5148\u96e2\u958b\u968a\u4f0d\uff0c\u7136\u5f8c\u63a5\u8457\u4e0b\u4e00\u4f4d\u540c\u5b78\u91cd\u65b0\u958b\u59cb\u6578 (\u6700\u5f8c\u4e00\u4f4d\u7684\u4e0b\u4e00\u500b\u662f\u7b2c\u4e00\u500b\uff09\uff0c<strong>\u6700\u5f8c\u5269\u4e0b\u7684\u90a3\u500b\u540c\u5b78\u5c31\u662f\u8868\u6f14\u624d\u85dd<\/strong>\uff0c\u8acb\u554f\u5728\u5df2\u77e5\u6578\u503c\u5f97\u72c0\u6cc1\u4e0b\uff0c<strong>\u4e00\u958b\u59cb\u7ad9\u5728\u54ea\u4e00\u500b\u4f4d\u7f6e\u7684\u4eba\u66fe\u662f\u8868\u6f14\u624d\u85dd\u7684\u4eba\u5462<\/strong>\uff1f<\/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\u4e00\u958b\u59cb\u662f\u4e00\u500b\u6574\u6578 T (1 &lt; T &lt; 10\uff09\uff0c\u4ee3\u8868\u5171\u6709 T \u7b46\u6e2c\u8a66\u8cc7\u6599\u3002<br>\u6bcf\u7d44\u6e2c\u8a66\u8cc7\u6599\u5171\u6709 2 \u884c\uff0c\u7b2c\u4e00\u884c\u8f38\u5165\u70ba\u4e00\u500b\u6b63\u6574\u6578 N\uff0c\u8868\u793a\u53c3\u52a0\u904a\u6232\u7684\u540c\u5b78\u4eba\u6578\u6709 N \u500b (0 &lt; N &lt; 100\uff09\uff0c\u7b2c\u4e8c\u884c\u8f38\u5165\u70ba\u4e00\u500b\u6b63\u6574\u6578 K \u8868\u793a\u6578\u5230 K \u7684\u540c\u5b78 PASS (K &lt; N\uff09\u3002<\/td><td>\u6bcf\u7b46\u6e2c\u8cc7\u8f38\u51fa\u70ba\u4e00\u500b\u6b63\u6574\u6578 P \u8868\u793a\u7b2c P \u4f4d\u540c\u5b78\u5fc5\u9808\u505a\u624d\u85dd\u8868\u6f14\uff0c\u6700\u5f8c\u5fc5\u9808\u6709\u63db\u884c\u5b57\u5143\u3002<\/td><\/tr><tr><td>2<br>15<br>4<br>85<br>2<\/td><td>13<br>43<\/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 Vector&lt;Pair&lt;int, int>>\uff0c\u5f9e\u7b2c 0 \u500b\u4f4d\u7f6e\u5230\u7b2c N-1 \u500b\u4f4d\u7f6e\u5206\u5225\u70ba\u6240\u6709\u4eba\uff0cPair \u5206\u5225\u5b58\u53d6\u6bcf\u4e00\u500b\u4eba\u7684\u4e0a\u4e00\u4f4d\u548c\u4e0b\u4e00\u4f4d\u662f\u8ab0 (Index)\u3002\u7576\u5c07\u67d0\u4e00\u500b\u4eba\u8e22\u51fa\u6642\uff0c\u66f4\u65b0\u9019\u500b\u4eba\u7684\u4e0a\u4e00\u4f4d\u548c\u4e0b\u4e00\u4f4d\uff0c\u4e0a\u4e00\u4f4d\u7684\u4e0b\u4e00\u4f4d\u8b8a\u6210\u88ab\u8e22\u6389\u7684\u4eba\u7684\u4e0b\u4e00\u4f4d\uff0c\u4e0b\u4e00\u4f4d\u7684\u4e0a\u4e00\u4f4d\u8b8a\u6210\u88ab\u8e22\u6389\u7684\u4eba\u7684\u4e0a\u4e00\u4f4d\u3002\u5ba3\u544a\u4e00\u500b Map&lt;int, int>\uff0c\u7576\u8e22\u6389\u4eba\u7684\u6642\u5019\u5c31\u5c07\u9019\u500b\u4eba\u7684 Index \u503c \u7684 Map +1\u3002\u7576\u8e22\u6389 N-1 \u500b\u4eba\u4e4b\u5f8c\uff0c\u8dd1 for (auto it:Map)\uff0c\u7576 it.second == 0 \u6642\uff0c\u4ee3\u8868 it.first \u6c92\u6709\u88ab\u8e22\u6389\uff0c\u8f38\u51fa it.first\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f Map \u9700\u8981\u5148\u5c07 0 \u5230 N-1 \u90fd\u521d\u59cb\u5316\u70ba 0\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/e-tutor.itsa.org.tw\/mod\/programming\/view.php?id=69431\" target=\"_blank\" rel=\"noreferrer noopener\">ITSA 202404 #2\uff1a\u9ede\u9ede\u540d<\/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;map&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int T;\n    cin &gt;&gt; T;\n    for (int i = 0; i&lt;T; i++)\n    {\n        int N, K;\n        cin &gt;&gt; N &gt;&gt; K;\n        vector&lt;pair&lt;int, int&gt;&gt;num;\n        map&lt;int, int&gt;MAP;\n        for (int j = 0; j&lt;N; j++)\n        {\n            pair&lt;int, int&gt;tmp;\n            tmp.first = j-1;\n            tmp.second = j+1;\n            if (j == 0) tmp.first = N-1;\n            if (j == N-1) tmp.second = 0;\n            num.push_back(tmp);\n            MAP[j] = 0;\n        }\n        int count = 0, kill = 0;\n        while (kill != N-1)\n        {\n            for (int j = 0; j&lt;K-1; j++)\n            {\n                count = num[count].second;\n            }\n            int next = num[count].second;\n            num[num[count].first].second = next;\n            num[num[count].second].first = num[count].first;\n            kill++;\n            MAP[count]++;\n            count = next;\n        }\n        for (auto it:MAP)\n        {\n            if (it.second == 0)\n            {\n                cout &lt;&lt; it.first+1 &lt;&lt; &quot;\\n&quot;;\n                break;\n            }\n        }\n    }\n}\n\n\/\/ITSA 202404 #2\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u67d0\u793e\u5718\u60f3\u73a9\u4e00\u500b\u904a\u6232\uff0c\u6709 N \u500b\u540c\u5b78\u6392\u6210\u4e00\u6392\uff0c\u4e00\u958b\u59cb\u5f9e 1 \u958b\u59cb\u6578\u5230 K\uff0c\u5c07\u7b2c K \u500b\u540c\u5b78\u5c31\u8868\u793aPASS\uff0c\u5148\u96e2\u958b [&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":[36],"tags":[14,23,20,8,9],"class_list":["post-587","post","type-post","status-publish","format-standard","hentry","category-itsa","tag-map","tag-pair","tag-20","tag-8","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/587","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=587"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/587\/revisions"}],"predecessor-version":[{"id":589,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/587\/revisions\/589"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}