{"id":1004,"date":"2024-08-01T09:00:00","date_gmt":"2024-08-01T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1004"},"modified":"2024-06-26T17:44:56","modified_gmt":"2024-06-26T09:44:56","slug":"zerojudge-n687","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-n687\/","title":{"rendered":"ZeroJudge N687: Rectangular Bananas"},"content":{"rendered":"<p>\"Rectangular bananas\" are a new variety of bananas that can only be grown in the intersection area of two rectangles.<\/p>\n\n\n\n<p>For example, here are some situations where rectangular bananas would be produced. When one rectangle is completely covered by another rectangle, it also counts as intersecting (as shown in the lower right diagram):<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"644\" height=\"269\" loading=\"lazy\" src=\"https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-6.png\" alt=\"ZeroJudge N687 \u77e9\u5f62\u9999\u8549\u4f8b\u5716\" class=\"wp-image-1009\" srcset=\"https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-6.png 644w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-6-300x125.png 300w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-6-18x8.png 18w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-6-50x21.png 50w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-6-100x42.png 100w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/figure>\n\n\n\n<p>Conversely, here are some situations where rectangular bananas would not be produced. \uff37hen two rectangles only touch edges, it does not count as intersecting (as shown in the lower left diagram):<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"625\" height=\"234\" loading=\"lazy\" src=\"https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-7.png\" alt=\"ZeroJudge N687 \u975e\u77e9\u5f62\u9999\u8549\u4f8b\u5716\" class=\"wp-image-1010\" srcset=\"https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-7.png 625w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-7-300x112.png 300w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-7-18x7.png 18w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-7-50x19.png 50w, https:\/\/seanxd.com\/wp-content\/uploads\/2024\/06\/image-7-100x37.png 100w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/figure>\n\n\n\n<p>Given two rectangles, please help calculate the area suitable for planting rectangular bananas.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sample Inputs\/Outputs<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><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\">You can input eight integers (x\u2081, y\u2081), (x\u2082, y\u2082), (x\u2083, y\u2083), (x\u2084, y\u2084) where:\n<br>\n(x\u2081, y\u2081) represents the bottom-left corner of the first rectangle.\n<br>\n(x\u2082, y\u2082) represents the top-right corner of the first rectangle.\n<br>\n(x\u2083, y\u2083) represents the bottom-left corner of the second rectangle.\n<br>\n(x\u2084, y\u2084) represents the top-right corner of the second rectangle.\n<br>\nThe coordinates are bounded between -100 and 100 for all x\u1d62 and y\u1d62.<\/td><td>Print the overlapping area of two rectangles; if there is no overlap, print \"banana\".<\/td><\/tr><tr><td>0 0 10 10 0 0 5 5<\/td><td>25<\/td><\/tr><tr><td>0 0 6 4 4 -4 7 2<\/td><td>4<\/td><\/tr><tr><td>2 2 3 3 3 2 4 3<\/td><td>banana<\/td><\/tr><tr><td>-2 1 1 4 1 -1 4 3<\/td><td>banana<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Thought Process<\/h2>\n\n\n\n<p>Calculate the left, right, upper, and lower boundaries of the overlapping part, named l (left), r (right), u (upper), and d (down).<\/p>\n\n\n\n<p>l is the maximum of x1 and x3, r is the minimum of x2 and x4, u is the minimum of y2 and y4, and d is the maximum of y1 and y3.<\/p>\n\n\n\n<p>If the four boundaries cannot form a rectangle, it means the two rectangles do not overlap. Specifically, this condition is met when l \u2265 r or d \u2265 u.<\/p>\n\n\n\n<p>If there is indeed an overlapping area, the area of overlap is calculated as (r\u2212l)\u00d7(u\u2212d).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=n687\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge N687: Rectangular Bananas<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap\"><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 x1, x2, x3, x4, y1, y2, y3, y4;\n    cin &gt;&gt; x1 &gt;&gt; y1 &gt;&gt; x2 &gt;&gt; y2 &gt;&gt; x3 &gt;&gt; y3 &gt;&gt; x4 &gt;&gt; y4;\n    const int l = max(x1, x3), r = min(x2, x4), u = min(y2, y4), d = max(y1, y3);\n    if (l &gt;= r || d &gt;= u) cout &lt;&lt; &quot;banana\\n&quot;;\n    else cout &lt;&lt; (r-l) * (u-d) &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/ZeroJudge N687\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u300c\u77e9\u5f62\u9999\u8549\u300d\u662f\u4e00\u7a2e\u65b0\u54c1\u7a2e\u7684\u9999\u8549\uff0c\u53ea\u80fd\u5920\u7a2e\u690d\u5728\u5169\u500b\u77e9\u5f62\u91cd\u758a\u4e5f\u5c31\u662f\u76f8\u4ea4\u7684\u5340\u57df\u3002 \u8209\u4f8b\u4f86\u8aaa\uff0c\u4ee5\u4e0b\u662f\u5176\u4e2d\u5e7e\u7a2e\u6703\u7522\u751f\u77e9\u5f62 [&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":[8,13],"class_list":["post-1004","post","type-post","status-publish","format-standard","hentry","category-6","tag-8","tag-13"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1004","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=1004"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1004\/revisions"}],"predecessor-version":[{"id":1012,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1004\/revisions\/1012"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1004"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}