{"id":591,"date":"2024-06-20T09:00:00","date_gmt":"2024-06-20T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=591"},"modified":"2024-05-17T21:22:22","modified_gmt":"2024-05-17T13:22:22","slug":"itsa-202404-4","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/itsa-202404-4\/","title":{"rendered":"ITSA 202404 #4: Defense System"},"content":{"rendered":"<p class=\"\">The kingdom of Abbasca was attacked by a neighboring country one day. Abbasca activated its Iron Wall air defense system. Due to limited resources, please help write a program to determine the most effective way to defend against the incoming missiles.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sample Inputs\/Outputs<\/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>Sample Input(s)<\/th><th>Sample Output(s)<\/th><\/tr><\/thead><tbody><tr><td>The first line contains one positive integer, N (1 \u2264 N \u2264 100), indicating the number of missiles approaching.<br>Following are N lines, each containing 2 positive integers, D and S (1 \u2264 S \u2264 4), where D represents the side length of the area to be defended (3 \u2264 D \u2264 9).<br>Check if S represents the direction of the missile attack:<br>When S equals 1, it indicates that the missile is approaching from the left front, so your missile defense system deployment should cover the upper right and lower left directions.<br>When S equals 2, it indicates that the missile is approaching from the right front, so your missile defense system deployment should cover the upper left and lower right directions.<br>When S equals 3, it indicates that the missile is approaching from the right side, so your missile defense system deployment should focus on the right side.<br>When S equals 4, it indicates that the missile is approaching from the left side, so your missile defense system deployment should focus on the left side.<\/td><td class=\"translation-block\">Please print the arrangement of the territory and the iron wall defense system, using '*' to represent the missile defense system and 'x' to represent the country.\n<br>\nThere should be a space between each '*' and 'x', and there must be a newline character at the end of each line.<\/td><\/tr><tr><td>2<br>3 1<br>4 3<\/td><td>x x *<br>x * x<br>* x x<br>x x x *<br>x x x *<br>x x x *<br>x x x *<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ITSA 202404 #4 \u7bc4\u4f8b\u6e2c\u8cc7<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Thought Process<\/h2>\n\n\n\n<p class=\"\">Using conditional statements to determine the value of S, if it is diagonal, initialize a variable to D-1 or 0 by default. Output \"\" each time the loop reaches this variable, and decrement or increment the variable accordingly. If S = 2, output \"\" only once per row, which can be confirmed using a boolean value.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/e-tutor.itsa.org.tw\/mod\/programming\/view.php?id=69433\" target=\"_blank\" rel=\"noreferrer noopener\">ITSA 202404 #4: Defense System<\/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;\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    for (int i = 0; i&lt;N; i++)\n    {\n        int D, S;\n        cin &gt;&gt; D &gt;&gt; S;\n        if (S == 1)\n        {\n            int count = D-1;\n            for (int j = 0; j&lt;D; j++)\n            {\n                for (int k = 0; k&lt;D; k++)\n                {\n                    if (k != 0) cout &lt;&lt; &quot; &quot;;\n                    if (k == count)\n                    {\n                        count--;\n                        cout &lt;&lt; &quot;*&quot;;\n                    }\n                    else cout &lt;&lt; &quot;x&quot;;\n                }\n                cout &lt;&lt; &quot;\\n&quot;;\n            }\n        }\n        else if (S == 2)\n        {\n            int count = 0;\n            for (int j = 0; j&lt;D; j++)\n            {\n                bool ok = true;\n                for (int k = 0; k&lt;D; k++)\n                {\n                    if (k != 0) cout &lt;&lt; &quot; &quot;;\n                    if (k == count && ok)\n                    {\n                        ok = false;\n                        count++;\n                        cout &lt;&lt; &quot;*&quot;;\n                    }\n                    else cout &lt;&lt; &quot;x&quot;;\n                }\n                cout &lt;&lt; &quot;\\n&quot;;\n            }\n        }\n        else if (S == 3)\n        {\n            for (int j = 0; j&lt;D; j++)\n            {\n                for (int k = 0; k&lt;D; k++)\n                {\n                    if (k != 0) cout &lt;&lt; &quot; &quot;;\n                    if (k == D-1) cout &lt;&lt; &quot;*&quot;;\n                    else cout &lt;&lt; &quot;x&quot;;\n                }\n                cout &lt;&lt; &quot;\\n&quot;;\n            }\n        }\n        else\n        {\n            for (int j = 0; j&lt;D; j++)\n            {\n                for (int k = 0; k&lt;D; k++)\n                {\n                    if (k != 0) cout &lt;&lt; &quot; &quot;;\n                    if (k == 0) cout &lt;&lt; &quot;*&quot;;\n                    else cout &lt;&lt; &quot;x&quot;;\n                }\n                cout &lt;&lt; &quot;\\n&quot;;\n            }\n        }\n    }\n}\n\n\/\/ITSA 202404 #4\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u963f\u5df4\u65af\u5361\u738b\u570b\u6709\u4e00\u5929\u906d\u53d7\u9130\u570b\u7684\u653b\u64ca\u3002\u963f\u5df4\u65af\u5361\u738b\u570b\u958b\u555f\u4e86\u9435\u7246\u9632\u7a7a\u7cfb\u7d71\uff0c\u56e0\u70ba\u8cc7\u6e90\u6709\u9650\uff0c\u8acb\u4f60\u5e6b\u5fd9\u5beb\u4e00\u500b\u7a0b\u5f0f\uff0c\u5224\u65b7\u8a72\u5982\u4f55 [&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":[8,34,9],"class_list":["post-591","post","type-post","status-publish","format-standard","hentry","category-itsa","tag-8","tag-34","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/591","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=591"}],"version-history":[{"count":3,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/591\/revisions"}],"predecessor-version":[{"id":594,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/591\/revisions\/594"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}