{"id":245,"date":"2024-04-26T22:32:17","date_gmt":"2024-04-26T14:32:17","guid":{"rendered":"https:\/\/seanxd.com\/?p=245"},"modified":"2024-04-26T22:32:19","modified_gmt":"2024-04-26T14:32:19","slug":"zerojudge-e520","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-e520\/","title":{"rendered":"ZeroJudge E520: Rockabye Tobby"},"content":{"rendered":"<h4 class=\"wp-block-heading\">UVa 13190 \u2013 Rockabye Tobby<\/h4>\n\n\n\n<p class=\"translation-block\">\"Rockabye baby, don\u2019t you cry.\" Tobby is very good at playing catch, and he likes this game. One day, he decided to go out and play, even though it was raining at the time. He played for a long time, and besides playing catch many times, he also got sick on the side, which was quite embarrassing and sad.\n\nThat's why his mother (Big Doggie) is taking care of him now. In addition to singing that beautiful lullaby (Rockabye), she also prepares medicine for him at specified times. The doctor's prescription specifies the name of the medicine and how often to take it. The doctor told him that if he followed the prescription and took K medicines, he would get better.\n\nTobby doesn't like being sick (actually, anyone does), so he assured his mother that he would take the medicine on time.\n\nThat's why he wants to know now which <strong>K medicines he must take first<\/strong> to get better and continue playing catch on rainy days. Can you help him?<\/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 class=\"translation-block\">For each case, the output must have K lines, each in the form \"t m\".\n\n\"t m\" indicates that Tobby must take medication m at time t.\n\nIf Tobby must take two or more medications at the same time t, the output should be based on their priority.<\/td><td>\u5c0d\u65bc\u6bcf\u500b Case\uff0c\u8f38\u51fa\u5fc5\u9808\u6709k\u884c\uff0c\u6bcf\u884c\u5f62\u5f0f\u70ba\u300ct m\u300d\u3002<br>\u300ct m\u300d\u8868\u793a\u5728 t \u6642\u523b Tobby \u5fc5\u9808\u670d\u7528\u85e5\u7269 m\u3002<br>\u5982\u679c\u5fc5\u9808\u5728\u540c\u4e00\u6642\u9593 t \u670d\u7528\u5169\u7a2e\u6216\u5169\u7a2e\u4ee5\u4e0a\u85e5\u7269\uff0c\u5247<strong>\u61c9\u6839\u64da\u5176\u512a\u5148\u7d1a\u9032\u884c\u8f38\u51fa<\/strong>).<\/td><\/tr><tr><td>1<br>2  5<br>Acetaminophen  20<br>Loratadine  30<\/td><td>20  Acetaminophen<br>30  Loratadine<br>40  Acetaminophen<br>60  Acetaminophen<br>60  Loratadine<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge E520 \u7bc4\u4f8b\u6e2c\u8cc7<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Thought Process<\/h2>\n\n\n\n<p class=\"translation-block\">Use a vector of pairs to store the names and frequencies of the medications. Then, use a while loop to check if the current time matches any medication that needs to be taken (i.e. if it is divisible by the frequency). It's important to check if the number of medications taken is equal to K after taking a medication. If it is, break the loop.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=e520\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge E520: Rockabye Tobby<\/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;\nusing namespace std;\n\npair&lt;string, int&gt; rtn (string name, int time)\n{\n    pair&lt;string, int&gt;tmp;\n    tmp.first = name;\n    tmp.second = time;\n    return tmp;\n}\n\nint main() {\n    int N;\n    cin &gt;&gt; N;\n    for (int i = 0; i&lt;N; i++)\n    {\n        int med, K;\n        cin &gt;&gt; med &gt;&gt; K;\n        vector&lt;pair&lt;string, int&gt;&gt;v;\n        for (int j = 0; j&lt;med; j++)\n        {\n            string name;\n            int time;\n            cin &gt;&gt; name &gt;&gt; time;\n            v.push_back(rtn(name, time));\n        }\n        int count = 0, j = 1;\n        while (count &lt; K)\n        {\n            for (auto it:v)\n            {\n                if (j % it.second == 0)\n                {\n                    cout &lt;&lt; j &lt;&lt; &quot; &quot; &lt;&lt; it.first &lt;&lt; &quot;\\n&quot;;\n                    count++;\n                    if (count &gt;= K) break;\n                }\n            }\n            j++;\n        }\n    }\n}\n\n\/\/ZeroJudge E520\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 13190 &#8211; Rockabye Tobby &#8220;Rockabye bab [&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":[23,20,8,11,13,9],"class_list":["post-245","post","type-post","status-publish","format-standard","hentry","category-uva","tag-pair","tag-20","tag-8","tag-11","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/245","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=245"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/245\/revisions"}],"predecessor-version":[{"id":247,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/245\/revisions\/247"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}