{"id":303,"date":"2024-04-27T17:16:40","date_gmt":"2024-04-27T09:16:40","guid":{"rendered":"https:\/\/seanxd.com\/?p=303"},"modified":"2024-04-27T17:16:42","modified_gmt":"2024-04-27T09:16:42","slug":"zerojudge-c079","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-c079\/","title":{"rendered":"ZeroJudge C079: Peter&#8217;s Smokes"},"content":{"rendered":"<h4 class=\"wp-block-heading\">UVa 10346 \u2013 Peter\u2019s Smokes<\/h4>\n\n\n\n<p class=\"translation-block\">Peter has N cigarettes, and he smokes them one by one, saving the leftover cigarette. <strong>When he accumulates K leftover cigarettes (where K &gt; 1), he can roll them into a new cigarette<\/strong>.<\/p>\n\n\n\n<p class=\"\">How many cigarettes can Peter smoke in total?<\/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><strong>EOF<\/strong> inputs: each test case consists of one line. Each line contains two integers, N and K.<\/td><td>For each input line, please output the total number of cigarettes Peter can smoke.<\/td><\/tr><tr><td>4  3<br>10  3<br>100  5<\/td><td>5<br>14<br>124<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Thought Process<\/h2>\n\n\n\n<p class=\"translation-block\">Use a <strong>While loop<\/strong> where <strong>after each cigarette is smoked, the number of leftover cigarettes increases by 1<\/strong>. Check if the current number of leftover cigarettes can be rolled into a new cigarette. If <strong>\"there are no cigarettes left\" &amp;&amp; \"the number of leftover cigarettes is less than K\"<\/strong>, then terminate the loop and output the answer.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=c079\" target=\"_blank\" rel=\"noopener\">ZeroJudge C07<\/a><a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=c079\" target=\"_blank\" rel=\"noreferrer noopener\">9<\/a><a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=c079\" target=\"_blank\" rel=\"noopener\">: Peter&#8217;s Smokes<\/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  int N, K;\n  while (cin &gt;&gt; N &gt;&gt; K)\n    {\n      int ans = 0, count = 0;\n      while (true)\n        {\n          if (N &gt; 0)\n          {\n            ans++;\n            count++;\n            N--;\n          }\n          else if (count &gt;= K)\n          {\n            ans++;\n            count-=K;\n            count++;\n          }\n          else break;\n        }\n      cout &lt;&lt; ans &lt;&lt; endl;\n    }\n}\n\n\/\/ZeroJudge C079\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 10346 &#8211; Peter&#8217;s Smokes Peter \u6709 N \u652f\u7d19\u7159 [&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":[8,13,9],"class_list":["post-303","post","type-post","status-publish","format-standard","hentry","category-uva","tag-8","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/303","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=303"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/303\/revisions"}],"predecessor-version":[{"id":304,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/303\/revisions\/304"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}