{"id":148,"date":"2024-04-26T14:46:46","date_gmt":"2024-04-26T06:46:46","guid":{"rendered":"https:\/\/seanxd.com\/?p=148"},"modified":"2024-04-26T14:46:48","modified_gmt":"2024-04-26T06:46:48","slug":"zerojudge-a518","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-a518\/","title":{"rendered":"ZeroJudge A518: Zapping"},"content":{"rendered":"<h3 class=\"wp-block-heading\">UVa 12468 \u2013 Zapping<\/h3>\n\n\n\n<p class=\"\">I'm a huge TV fan, but I don't like sticking to one channel. I often switch between different channels.<\/p>\n\n\n\n<p class=\"\">My dog chewed up my remote control, and now the number buttons don't work. I'm left with only two buttons to change channels: one for going up (\u25b3 button) and one for going down (\u25bd button). It's really annoying because if I want to switch from channel 3 to channel 9, I have to press the \u25b3 button 6 times.<\/p>\n\n\n\n<p class=\"\">\u6211\u7684\u96fb\u8996\u6709<strong> 100 \u500b\u983b\u9053\uff0c\u865f\u78bc\u70ba 0 \u5230 99<\/strong>\u3002\u5b83\u5011\u662f<strong>\u5faa\u74b0\u7684<\/strong>\uff0c\u4e5f\u5c31\u662f\u5f9e 99 \u53f0\u518d\u6309\u4e00\u4e0b \u25b3 \u5c31\u6703\u56de\u5230\u7b2c 0 \u53f0\u3002\u540c\u7406\uff0c\u5f9e\u7b2c 0 \u53f0\u6309\u4e00\u4e0b \u25bd \u5c31\u6703\u56de\u5230 99 \u53f0\u3002<\/p>\n\n\n\n<p class=\"translation-block\">Can you help me write a program that, given the current channel I'm watching and the channel I want to switch to, tells me the minimum number of button presses needed?<\/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 nfd-delay-50\"><table class=\"has-fixed-layout\"><thead><tr><th>Sample Input(s)<\/th><th>Sample Output(s)<\/th><\/tr><\/thead><tbody><tr><td>The input consists of multiple test cases, terminated by EOF (End of File). Up to 200 test cases may be present.<br>Each test case consists of a single line containing two integers, a and b. a represents the current channel, and b represents the channel to switch to. Both a and b are non-negative integers not exceeding 99.<br>The last line consists of two -1 integers and should not be processed.<\/td><td class=\"translation-block\">For each set of data, output an integer on a single line, representing the minimum number of button presses required to switch to the new channel. (Remember, I only have two buttons available: \u25b3 and \u25bd).<\/td><\/tr><tr><td>3  9<br>0  99<br>12  27<br>-1  -1<\/td><td>6<br>1<br>15<\/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\">Calculate both the values of \"\u25b3\" and \"\u25bd\", then compare them to find the smaller value and output that smaller value.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a518\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge A518: Zapping<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right nfd-delay-150\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nint main() {\n    int a, b;\n    while (cin &gt;&gt; a &gt;&gt; b)\n    {\n        if (a == -1 && b == -1) break;\n        else\n        {\n            if (a &gt; b) swap(a, b);\n            int one = b - a;\n            int two = a - b + 100;\n            cout &lt;&lt; min(one, two) &lt;&lt; endl;\n        }\n    }\n}\n\n\/\/ZeroJudge A518\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 12468 &#8211; Zapping \u6211\u662f\u500b\u8d85\u7d1a\u96fb\u8996\u8ff7\uff0c\u4f46\u662f\u6211\u4e0d\u559c\u6b61\u56fa\u5b9a\u770b\u4e00\u500b\u983b\u9053\uff0c\u6211\u7d93\u5e38 [&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],"class_list":["post-148","post","type-post","status-publish","format-standard","hentry","category-uva","tag-8","tag-13"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/148","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=148"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":149,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/148\/revisions\/149"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}