{"id":396,"date":"2024-04-29T16:06:21","date_gmt":"2024-04-29T08:06:21","guid":{"rendered":"https:\/\/seanxd.com\/?p=396"},"modified":"2024-04-29T16:06:23","modified_gmt":"2024-04-29T08:06:23","slug":"zerojudge-h658","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-h658\/","title":{"rendered":"ZeroJudge H658: Fishing"},"content":{"rendered":"<p class=\"translation-block\">Xiao Ming is a fisherman who goes out to sea in his boat every day to catch fish. Fishing is his passion, and to catch as many fish as possible efficiently, he <strong>uses the radar system on his boat to detect nearby schools of fish<\/strong>, thereby determining the <strong>distance between each school and his boat<\/strong>, allowing him to start fishing from the nearest location. Xiao Ming hopes to quickly find the <strong>nearest school of fish<\/strong> using a program, so he's asking for your help.<\/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\">The first line of input consists of two integers X and Y (0 \u2264 X, Y \u2264 500) representing the fisherman's coordinates. The second line contains an integer N (1 \u2264 N \u2264 100) representing the number of fish schools. Following that, there are N lines, each containing two integers A<sub>i<\/sub> and B<sub>i<\/sub> (0 \u2264 A<sub>i<\/sub>, B<sub>i<\/sub> \u2264 500, 1 \u2264 i \u2264 N) indicating the coordinates of the center of each fish school.<\/td><td>Output two integers representing the coordinates of the center of the nearest fish school to the fisherman, ensuring that there is only one nearest fish school.<\/td><\/tr><tr><td>5  6<br>1<br>10  10<\/td><td>10  10<\/td><\/tr><tr><td>8  2<br>3<br>7  9<br>10  3<br>5  1<\/td><td>10  3<\/td><\/tr><tr><td>20  15<br>7<br>25  34<br>100  0<br>12  51<br>3  9<br>37  22<br>10  71<br>2  36<\/td><td>3  9<\/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\">Because calculating distances between coordinates may involve rounding errors due to rounding up or down, which could lead to incorrect determination of the minimum value, <strong>you can avoid calculating the square root when computing distances<\/strong>. Use a for loop to calculate the distance between each coordinate and the boat, then select the minimum value.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=h658\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge H658: Fishing<\/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;math.h&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int x, y;\n    cin &gt;&gt; x &gt;&gt; y;\n    int N;\n    cin &gt;&gt; N;\n    int ans = 9999999;\n    pair&lt;int, int&gt;loc;\n    for (int i = 0; i&lt;N; i++)\n    {\n        int a, b;\n        cin &gt;&gt; a &gt;&gt; b;\n        int dis = pow(a-x, 2) + pow(b-y, 2);\n        if (dis &lt; ans)\n        {\n            ans = dis;\n            loc.first = a;\n            loc.second = b;\n        }\n    }\n    cout &lt;&lt; loc.first &lt;&lt; &quot; &quot; &lt;&lt; loc.second &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/ZeroJudge H658\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u660e\u662f\u540d\u6f01\u7fc1\uff0c\u6bcf\u5929\u90fd\u6703\u5230\u958b\u8457\u8239\u5230\u5927\u6d77\u53bb\u6355\u9b5a\u3002\u6355\u9b5a\u662f\u4ed6\u71b1\u611b\u7684\u8208\u8da3\uff0c\u70ba\u4e86\u66f4\u6709\u6548\u7387\u7684\u6355\u7372\u6700\u591a\u7684\u9b5a\uff0c\u5c0f\u660e\u6703\u5229\u7528\u8239\u4e0a\u7684\u96f7 [&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":[25],"tags":[8,13,9],"class_list":["post-396","post","type-post","status-publish","format-standard","hentry","category-ioi-apcs","tag-8","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/396","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=396"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/396\/revisions"}],"predecessor-version":[{"id":397,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/396\/revisions\/397"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}