#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 time |
Memory |
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 |
- |