제출 #975636

#제출 시각아이디문제언어결과실행 시간메모리
975636vjudge1별들과 삼각형 (IZhO11_triangle)C++17
0 / 100
1 ms344 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int N; vector<pair<int, int>> points; bool isRightTriangle(int x1, int y1, int x2, int y2, int x3, int y3) { // Calculate the side lengths int a = abs(x2 - x1); int b = abs(y2 - y1); int c = abs(x3 - x1); int d = abs(y3 - y1); // Check if the triangle is right-angled if ((a == 0 && c == 0) || (b == 0 && d == 0)) { // No right-angled triangle if two points have the same x or y coordinate return false; } // Check if the triangle has sides parallel to the X and Y axes if ((a == c && b == d) || (a == d && b == c)) { return a * a + b * b == c * c + d * d; } return false; } int countRightTriangles() { int count = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { for (int k = j + 1; k < N; k++) { if (isRightTriangle(points[i].first, points[i].second, points[j].first, points[j].second, points[k].first, points[k].second)) { count++; } } } } return count; } int main() { cin >> N; points.resize(N); for (int i = 0; i < N; i++) { cin >> points[i].first >> points[i].second; } cout << countRightTriangles() << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...