{"id":94,"date":"2024-04-26T10:06:23","date_gmt":"2024-04-26T02:06:23","guid":{"rendered":"https:\/\/seanxd.com\/?p=94"},"modified":"2024-04-26T10:31:47","modified_gmt":"2024-04-26T02:31:47","slug":"zerojudge-a271","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-a271\/","title":{"rendered":"ZeroJudge A271: Colored Radish"},"content":{"rendered":"\n\n\n<p class=\"\">\u5728\u4e00\u500b\u795e\u5947\u7684\u570b\u5ea6\u88e1\uff0c\u6709\u4e00\u7a2e\u5154\u5b50\uff0c\u5b83\u53ea\u5403\u863f\u8514\uff0c\u4e14\u6bcf\u5929\u53ea\u5403\u4e00\u500b\uff0c\u863f\u8514\u6709\u56db\u7a2e\u984f\u8272\uff0c\u5206\u5225\u70ba\uff1a\u7d05\u863f\u8514\uff0c\u767d\u863f\u8514\uff0c\u9ec3\u863f\u8514\uff0c\u767c\u9709\u7684\u863f\u8514\uff08\u9ed1\u8272\uff09\uff0c\u5154\u5b50\u5403\u4e86\u863f\u8514\u4e4b\u5f8c\uff0c\u9ad4\u91cd\u6703\u6709\u4e0d\u540c\u7684\u8b8a\u5316\uff0c<strong>\u7d05\u863f\u8514\u5403\u4e86\u80d6xg<\/strong>\uff0c<strong>\u767d\u863f\u8514\u5403\u4e86\u80d6yg<\/strong>\uff0c<strong>\u9ec3\u863f\u8514\u5403\u4e86\u7626zg<\/strong> (\u9183\u9ec3\u863f\u8514\u771f\u96e3\u5403&#8230;)\uff0c<strong>\u767c\u9709\u7684\u863f\u8514\u5403\u4e86\u7626wg<\/strong> <strong>(\u9644\u52a0\u72c0\u614b\uff1a\u4e2d\u6bd2&#8230;)<\/strong>\uff0c\u73fe\u5728\u7d66\u4f60x,y,z,w\u554f\u4f60\u5e7e\u5929\u5f8c\uff0c\u5154\u5b50\u7684\u9ad4\u91cd\uff01<\/p>\n\n\n\n<p class=\"\">P.S. \u4e2d\u6bd2\u6703\u4f7f\u5154\u5b50\u6bcf\u5929\u7626ng(\u4e2d\u6bd2\u7576\u5929\u4e0d\u7b97),\u4e14\u4e2d\u6bd2\u72c0\u614b\u53ef\u7d2f\u52a0\uff0cm\u662f\u5154\u5b50\u521d\u59cb\u7684\u9ad4\u91cd\u3002<strong>\u65e9\u4e0a\u5148\u4e2d\u6bd2\uff0c\u665a\u4e0a\u624d\u5403\u6771\u897f<\/strong>\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\u662f\u6e2c\u8cc7\u7684\u7b46\u6578\uff0c\u6bcf\u7b46\u6e2c\u8cc7<strong>\u7b2c\u4e00\u884c\u662f x\u3001y\u3001z\u3001w\u3001n\u3001m<\/strong>\uff0c\u7b2c\u4e8c\u884c\u662f\u4e00\u4e32\u6578\u5b57\uff0c1\u4ee3\u8868\u7d05\u863f\u8514\uff0c2\u4ee3\u8868\u767d\u863f\u8514\uff0c3\u4ee3\u8868\u9ec3\u863f\u8514\uff0c4\u4ee3\u8868\u9ed1\u863f\u8514\uff0c0\u4ee3\u8868\u6c92\u5403\u3002\u9019\u4e00\u884c\u4e2d\u7684\u6578\u5b57\u70ba\u5154\u5b50\u9019\u6bb5\u6642\u9593\u5167\u6240\u5403\u7684\u98df\u7269\u3002<\/td><td>\u8acb\u8f38\u51fa\u5154\u5b50\u5728\u90a3\u6bb5\u6642\u9593\u5f8c\u6240\u5269\u7684\u9ad4\u91cd\uff0c\u5982\u679c\u9ad4\u91cd\u6709\u5728\u4efb\u610f\u6642\u523b\u5c11\u65bc\u7b49\u65bc0\u8acb\u8f38\u51fa\uff1a\u300cbye~Rabbit\u300d\uff0c\u4e0d\u7136\u8acb\u5370\u51fa\u7d50\u675f\u6642\u7684\u9ad4\u91cd\u3002<br>\u6709\u53ef\u80fd\u554f\u4f60\u7b2c\u4e00\u5929\u7684\u9ad4\u91cd\u6b50\uff01(\u5c31\u662f\u554f\u521d\u59cb\u9ad4\u91cd\uff0c\u4e5f\u5c31\u662f\u90a3\u884c\u6839\u672c\u6c92\u8f38\u5165)<br>\u4f8b\u5982\u5982\uff1a<br>13 312 43 432 567<br>\/\/\u7a7a\u4e00\u884c<br>\u8f38\u51fa\u70ba\uff1a567<\/td><\/tr><tr><td>4<br><strong>5  3  2  4  3  10<\/strong><br>1  1  2  3  3  3  3  4  3  3<br><strong>5  3  2  4  3  10<\/strong><br>1  1  2  3  3  3  3  4  3  3  2  2  2  2  2  2  2<br><strong>5  3  2  4  3  10<\/strong><br>4  1  3  3  1  1  2  2  1  1  3  1  1  1  1  4<br><strong>10  3  2  2  1  5<\/strong><br>1  4  4  0  0  4  1  2  2  2  0  0  2  2  0<\/td><td>1g<br>bye~Rabbit<br>bye~Rabbit<br>bye~Rabbit<\/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=\"\">\u4f7f\u7528<strong>\u5b57\u4e32<\/strong>\u7684\u65b9\u5f0f\u5c07\u6bcf\u7b46\u8cc7\u6599\u7684\u7b2c\u4e8c\u884c\u5b58\u8d77\u4f86\u3002\u63a5\u4e0b\u4f86\u53ef\u4ee5\u4f7f\u7528<strong>For\u8ff4\u5708<\/strong>\u5c07\u4e0d\u662f\u7a7a\u767d\u7684\u5b57\u5143\u5b58\u5230\u4e00\u500b<strong>\u9663\u5217<\/strong>\u88e1 (\u56e0\u7b2c\u4e8c\u884c\u7684\u6574\u6578\u53ea\u6703\u6709\u500b\u4f4d\u6578)\u3002\u4e4b\u5f8c\u518d\u4f7f\u7528<strong>For\u8ff4\u5708<\/strong>\u4f86\u505a\u5224\u65b7\u5154\u5b50\u9ad4\u91cd\u7684\u589e\u6e1b\u3002\u66f4\u9ad8\u968e\u7684\u65b9\u5f0f\u53ef\u4ee5\u4f7f\u7528<strong>StringStream<\/strong>\u4f86\u9032\u884c\u89e3\u984c\u3002\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4e00\u958b\u59cbcin\u5b8c6\u500b\u6574\u6578\u4e4b\u5f8c\u8981\u5148\u505a\u4e00\u6b21\u6c92\u6709\u610f\u7fa9\u7684<strong>getline<\/strong>\u4e0d\u7136<strong>getline<\/strong>\u6703\u5931\u6548\u9019\u9ede\u8981\u6ce8\u610f\uff0c\u6216\u8005\u662f\u4f7f\u7528<strong>cin.ignore()<\/strong>\u4e5f\u53ef\u4ee5\u3002\u70ba\u4e86\u907f\u514d<strong>TLE<\/strong>\uff0c\u5728\u505a\u9ad4\u91cd\u589e\u6e1b\u5224\u65b7\u6642\uff0c\u5982\u679c\u5df2\u7d93\u767c\u73fe\u5154\u5b50\u7684<strong>\u9ad4\u91cd\u5c0f\u65bc0<\/strong>\uff0c\u53ef\u4ee5\u76f4\u63a5\u628aFor\u8ff4\u5708<strong>break<\/strong>\u6389\uff0c\u7136\u5f8c\u4f7f\u7528<strong>\u5e03\u6797\u503c<\/strong>\u4f86\u5224\u65b7\u662f\u5426\u8981\u8f38\u51fa\u5154\u5b50\u7576\u524d\u7684\u9ad4\u91cd\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a271\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge A271: \u5f69\u8272\u863f\u8514<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;string&gt;\nusing namespace std;\n\nint main() {\n  int N;\n  int red, white, yellow, black, poison, current;\n  cin &gt;&gt; N;\n  string str;\n  for (int i = 0; i&lt;N; i++)\n    {\n      cin &gt;&gt; red &gt;&gt; white &gt;&gt; yellow &gt;&gt; black &gt;&gt; poison &gt;&gt; current;\n      getline(cin , str);\n      getline(cin, str);\n      int carrots[10000] = {};\n      int tmp = 0;\n      int count = 0;\n      bool dead = false;\n      for (int j = 0; j&lt;str.length(); j++)\n        {\n          if (str[j] != &#39; &#39;)\n          {\n            carrots[tmp] = str[j] - &#39;0&#39;;\n            tmp += 1;\n          }\n        }\n      for (int i = 0; i&lt;tmp; i++)\n        {\n          current -= count * poison;\n          if (current &lt;= 0)\n          {\n            cout &lt;&lt; &quot;bye~Rabbit&quot; &lt;&lt; endl;\n            dead = true;\n            break;\n          }\n          \n          if (carrots[i] == 1)\n          {\n            current += red;\n          }\n          else if (carrots[i] == 2)\n          {\n            current += white;\n          }\n          else if (carrots[i] == 3)\n          {\n            current -= yellow;\n          }\n          else if (carrots[i] == 4)\n          {\n            current -= black;\n            count += 1;\n          }\n          \n          if (current &lt;= 0)\n          {\n            cout &lt;&lt; &quot;bye~Rabbit&quot; &lt;&lt; endl;\n            dead = true;\n            break;\n          }\n        }\n      if (!dead)\n      {\n        cout &lt;&lt; current &lt;&lt; &quot;g&quot; &lt;&lt; endl;\n      }\n    }\n}\n\n\/\/ZeroJudge A271\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4e00\u500b\u795e\u5947\u7684\u570b\u5ea6\u88e1\uff0c\u6709\u4e00\u7a2e\u5154\u5b50\uff0c\u5b83\u53ea\u5403\u863f\u8514\uff0c\u4e14\u6bcf\u5929\u53ea\u5403\u4e00\u500b\uff0c\u863f\u8514\u6709\u56db\u7a2e\u984f\u8272\uff0c\u5206\u5225\u70ba\uff1a\u7d05\u863f\u8514\uff0c\u767d\u863f\u8514\uff0c\u9ec3\u863f\u8514\uff0c\u767c [&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":[6],"tags":[20,8,11,12,9],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-6","tag-20","tag-8","tag-11","tag-12","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/94","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=94"}],"version-history":[{"count":3,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":97,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/94\/revisions\/97"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}