# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
975636 | vjudge1 | Star triangles (IZhO11_triangle) | C++17 | 1 ms | 344 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |