题意:求有n个点能组成几个锐角三角形,很容易想到:a^2+b^2 > c^2 (c应该是最大的),考虑了精度问题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 2005;
#define eps 1e-9
struct node{
double x,y;
};
int check(node a,node b,node c){
double ans[3];
ans[0] = (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
ans[1] = (a.x-c.x)*(a.x-c.x) + (a.y-c.y)*(a.y-c.y);
ans[2] = (b.x-c.x)*(b.x-c.x) + (b.y-c.y)*(b.y-c.y);
sort(ans,ans+3);
if (ans[2] < ans[0]+ans[1]+eps)
return 1;
else return 0;
}
int main(){
int t;
scanf("%d",&t);
while (t--){
int n;
node map[MAXN];
scanf("%d",&n);
for (int i = 0; i < n; i++)
scanf("%lf%lf",&map[i].x,&map[i].y);
int cnt = 0;
for (int i = 0; i < n-2; i++)
for (int j = i+1; j < n-1; j++)
for (int k = j+1; k < n; k++)
if (check(map[i],map[j],map[k]))
cnt++;
printf("%d\n",cnt);
}
return 0;
}