답안 #975636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975636 2024-05-05T15:19:26 Z vjudge1 별들과 삼각형 (IZhO11_triangle) C++17
0 / 100
1 ms 344 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -