# ZeroJudge - b557: 直角三角形 ### 題目連結:https://zerojudge.tw/ShowProblem?problemid=b557 ###### tags: `ZeroJudge` `數學` `幾何` ```cpp= #include <iostream> #include <unordered_map> #include <vector> #include <cmath> using namespace std; static const auto Initialize = [] { cin.sync_with_stdio(false); cin.tie(nullptr); return nullptr; }(); int main() { int times, amount, edgeLnegth, counts; unordered_map <int, int> edges; cin >> times; while (times--) { edges.clear(); counts = 0; cin >> amount; while (amount--) { cin >> edgeLnegth; ++edges[edgeLnegth]; } for (unordered_map <int, int>::iterator i = edges.begin(); i != edges.end(); ++i) for (unordered_map <int, int>::iterator j = i; j != edges.end(); ++j) if (i != j) { edgeLnegth = int(hypot(i->first, j->first)); if (edgeLnegth * edgeLnegth == (i->first * i->first) + (j->first * j->first) && edges.count(edgeLnegth)) counts += i->second * j->second * edges[edgeLnegth]; } cout << counts << '\n'; } } ```