{"id":737,"date":"2024-07-14T09:00:00","date_gmt":"2024-07-14T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=737"},"modified":"2024-06-05T20:03:51","modified_gmt":"2024-06-05T12:03:51","slug":"zerojudge-n803","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-n803\/","title":{"rendered":"ZeroJudge N803: The Coco-Cola Store"},"content":{"rendered":"<h4 class=\"wp-block-heading\">UVa 11877 \u2013 The Coco-Cola Store<\/h4>\n\n\n\n<p class=\"translation-block\">Once upon a time, there was a special Coca-Cola store. If you return three empty bottles to the store, you will receive one full bottle of Coca-Cola to drink. If you have N empty bottles, how many bottles of Coca-Cola can you drink at most?<\/p>\n\n\n\n<p class=\"translation-block\">Hint: Let me tell you how to drink 5 bottles of Coca-Cola with 10 empty bottles: Use 9 empty bottles to exchange for 3 full bottles, drink them to get 3 empty bottles, then use these empty bottles to exchange for one full bottle. Now you have 2 empty bottles. Borrow one empty bottle from the store, then exchange for one full bottle. Drink it, and finally return the last empty bottle to the store.<\/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\">EOF input. Each test case consists of one line containing an integer N (1 \u2264 N \u2264 100). The input ends with N = 0, which should not be processed.<\/td><td>For each test case, output the number of full bottles of Coca-Cola you can drink.<\/td><\/tr><tr><td>3<br>10<br>81<br>0<\/td><td>1<br>5<br>40<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Thought Process<\/h2>\n\n\n\n<p class=\"\">Use a while loop (N &gt;= 3). Inside the loop, declare a variable 'bottle' representing the number of Coca-Cola bottles you can drink, which is N\/3. Then, update the answer += bottle, N -= bottle*3, and N += bottle.<\/p>\n\n\n\n<p class=\"\">Since you can borrow empty bottles from the store, add a conditional statement outside the while loop. If N == 2 after the while loop ends, it means you can borrow a bottle, so increment the answer by 1.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=n803\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge N803: The Coco-Cola Store<\/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    while (cin &gt;&gt; N && N != 0) {\n        int ans = 0;\n        while (N &gt;= 3) {\n            int bottle = N\/3;\n            ans += bottle;\n            N -= bottle*3;\n            N += bottle;\n        }\n        if (N == 2) ans++;\n        cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge N803\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 11877 &#8211; The Coco-Cola Store \u5f9e\u524d\uff0c\u6709\u4e00\u5bb6\u7279\u5225\u7684\u53ef\u53e3\u53ef\u6a02\u5546 [&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-737","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\/737","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=737"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/737\/revisions"}],"predecessor-version":[{"id":738,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/737\/revisions\/738"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}