{"id":379,"date":"2024-04-29T15:04:49","date_gmt":"2024-04-29T07:04:49","guid":{"rendered":"https:\/\/seanxd.com\/?p=379"},"modified":"2024-04-29T15:04:51","modified_gmt":"2024-04-29T07:04:51","slug":"zerojudge-b557","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-b557\/","title":{"rendered":"ZeroJudge B557: \u76f4\u89d2\u4e09\u89d2\u5f62"},"content":{"rendered":"\n\n\n<p class=\"\">\u4f60\u4eca\u5929\u6709 N \u500b\u9577\u5ea6\u4e0d\u7b49\u7684\u6728\u68d2\uff0c\u800c\u4f60\u60f3\u77e5\u9053<strong>\u9019\u4e9b\u6728\u68d2\u80fd\u7d44\u5408\u51fa\u5e7e\u7a2e\u300c\u76f4\u89d2\u4e09\u89d2\u5f62\u300d<\/strong>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/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>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>\u7b2c\u4e00\u884c\u6709\u4e00\u6578\u5b57 T \uff0c\u4ee3\u8868\u6709\u5e7e\u7d44\u6e2c\u8a66\u8cc7\u6599 (1 &lt;= T &lt;= 50)<br>\u6bcf\u7d44\u6e2c\u8a66\u8cc7\u6599\u5305\u542b\u5169\u884c<br>\u7b2c\u4e00\u884c\u6709\u4e00\u6578\u5b57 N \uff0c\u4ee3\u8868\u6709\u5e7e\u6839\u6728\u68d2 (1 &lt;= N &lt;= 100)<br>\u7b2c\u4e8c\u884c\u6709 N \u500b\u6578\u5b57 a<sub>i<\/sub> \u4ee5\u7a7a\u767d\u9694\u958b\uff0c\u4ee3\u8868\u6728\u68d2\u7684\u9577\u5ea6 (1 &lt;= a<sub>i<\/sub> &lt;= 100)<\/td><td>\u5c0d\u65bc\u6bcf\u7b46\u6e2c\u8a66\u8cc7\u6599\u8f38\u51fa\u4e00\u884c\uff0c\u6bcf\u884c\u5305\u542b\u4e00\u500b\u6578\u5b57 x \u4ee3\u8868\u53ef\u4ee5\u7d44\u6210\u5e7e\u7a2e\u76f4\u89d2\u4e09\u89d2\u5f62\u3002<\/td><\/tr><tr><td>3<br>3<br>3  4  5<br>6<br>3  3  4  4  5  5<br>3<br>3  4  6<\/td><td>1<br>8<br>0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\">\u6536\u8cc7\u6599\u7684\u6642\u5019<strong>\u540c\u4e00\u500b\u6578\u5b57\u53ea\u9700\u6536\u4e00\u6b21\uff0c\u4f46\u662f\u8981\u7528 Map \u7d00\u9304\u9019\u500b\u6578\u5b57\u51fa\u73fe\u7684\u6b21\u6578<\/strong>\uff0c\u4e26\u4e14<strong>\u5b58\u653e\u5230\u9663\u5217\u7684\u6642\u5019\u53ef\u4ee5\u5148\u5c07\u8cc7\u6599\u9032\u884c\u5e73\u65b9<\/strong>\u3002<\/p>\n\n\n\n<p class=\"\">\u5c07<strong>\u9663\u5217\u6392\u5e8f<\/strong>\u904e\u5f8c\u4f7f\u7528<strong>\u5169\u500b For\u8ff4\u5708 \u4f86\u53d6\u9663\u5217\u4e2d\u7684\u4efb\u610f\u5169\u6578<\/strong>\uff0c\u4ee3\u8868 a^2 + b^2 = c^2 \u7684 a \u548c b\u3002<strong>\u53ea\u9700\u5224\u65b7 c \u662f\u5426\u5728Map\u4e2d\u6709\u8d85\u904e\u4e00\u500b\u6578\u91cf\u5c31\u53ef\u4ee5\u5224\u65b7\u9019\u6a23\u7684\u7d44\u5408\u662f\u5426\u70ba\u76f4\u89d2\u4e09\u89d2\u5f62<\/strong>\u3002<\/p>\n\n\n\n<p class=\"\">\u56e0\u70ba\u540c\u4e00\u500b\u6578\u5b57\u53ef\u80fd\u6703\u8d85\u904e\u4e00\u500b\uff0c\u6240\u4ee5<strong>\u7b54\u6848\u8981 += MAP[a] * MAP[b] * MAP[c]<\/strong>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=b557\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge B557: \u76f4\u89d2\u4e09\u89d2\u5f62<\/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;map&gt;\n#include &lt;vector&gt;\n#include &lt;algorithm&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 T;\n    cin &gt;&gt; T;\n    for (int i = 0; i&lt;T; i++)\n    {\n        vector&lt;int&gt;num;\n        map&lt;int, int&gt;MAP;\n        int N, ans = 0;\n        cin &gt;&gt; N;\n        for (int j = 0; j&lt;N; j++)\n        {\n            int tmp;\n            cin &gt;&gt; tmp;\n            tmp = pow(tmp, 2);\n            if (MAP[tmp] == 0) num.push_back(tmp);\n            MAP[tmp]++;\n        }\n        sort(num.begin(), num.end());\n        for (int j = 0; j&lt;num.size(); j++)\n        {\n            for (int k = j+1; k&lt;num.size(); k++)\n            {\n                int c = num[j] + num[k];\n                if (MAP[c] &gt; 0) ans += MAP[num[j]] * MAP[num[k]] * MAP[c];\n            }\n        }\n        cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge B557\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4f60\u4eca\u5929\u6709 N \u500b\u9577\u5ea6\u4e0d\u7b49\u7684\u6728\u68d2\uff0c\u800c\u4f60\u60f3\u77e5\u9053\u9019\u4e9b\u6728\u68d2\u80fd\u7d44\u5408\u51fa\u5e7e\u7a2e\u300c\u76f4\u89d2\u4e09\u89d2\u5f62\u300d\u3002 \u7bc4\u4f8b\u6e2c\u8cc7 \u7bc4\u4f8b\u8f38\u5165 \u7bc4\u4f8b\u8f38\u51fa  [&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":[14,20,8,13,9],"class_list":["post-379","post","type-post","status-publish","format-standard","hentry","category-6","tag-map","tag-20","tag-8","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/comments?post=379"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/379\/revisions"}],"predecessor-version":[{"id":380,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/379\/revisions\/380"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}