数三角
数三角
http://www.nowcoder.com/questionTerminal/06763b319e75433daea6f24e99d47d03
数三角
https://ac.nowcoder.com/acm/contest/3003/D
先使用数组记录任意两个点所连的边,再进行钝角判断
a^2+b^2<c^2
#pragma warning (disable :4996)
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll San[550][550];
struct Point {
ll x, y;
};
ll sum = 0;
ll a, b, c;
void Max() {
if (a > b) {
ll tmp = a;
a = b, b = tmp;
}
if (a > c) {
ll tmp = a;
a = c, c = tmp;
}
if (b > c) {
ll tmp = b;
b = c, c = tmp;
}
}
int main()
{
int n;
ll x, y;
Point S[550];
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld %lld", &x, &y);
S[i].x = x, S[i].y = y;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j)
San[i][j] = 0;
else
San[i][j] = (S[i].x - S[j].x) * (S[i].x - S[j].x) + (S[i].y - S[j].y) * (S[i].y - S[j].y);
}
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
for (int k = j + 1; k <= n; k++) {
a = San[i][j];
b = San[i][k];
c = San[j][k];
Max();
if (b + a < c) {
if ((S[i].y - S[j].y) * 1.0 / (S[i].x - S[j].x) * 1.0 == (S[i].y - S[k].y) * 1.0 / (S[i].x - S[k].x) * 1.0)
continue;
sum++;
}
}
}
}
cout << sum << endl;
}
