C. Star
1000ms
1000ms
32768KB
Font Size:
Overpower often go to the playground with classmates. They play and chat on the playground. One day, there are a lot of stars in the sky. Suddenly, one of Overpower’s classmates ask him: “How many acute triangles whose inner angles are less than 90 degrees (regarding stars as points) can be found? Assuming all the stars are in the same plane”. Please help him to solve this problem.
Input
The first line of the input contains an integer T (T≤10), indicating the number of test cases.
For each test case:
The first line contains one integer n (1≤n≤100), the number of stars.
The next n lines each contains two integers x and y (0≤|x|, |y|≤1,000,000) indicate the points, all the points are distinct.
Output
For each test case, output an integer indicating the total number of different acute triangles.
Sample Input
1 3 0 0 10 0 5 1000
Sample Output
1
//题意:每个样例给出n,然后n个坐标,求这些点能组成多少个锐角三角形
//思路:只要知道锐角三角形三边的关系a^2+b^2>c^2即可.
#include<stdio.h>
#include<math.h>
int main()
{
int t,n,i,j,k,time;
double s[101][2];
double a,b,c,x1,y1,x2,y2,x3,y3;
scanf("%d",&t);
while(t--)
{
time=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%lf%lf",&s[i][0],&s[i][1]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
for(k=j+1;k<n;k++)
{
x1=s[i][0];y1=s[i][1];
x2=s[j][0];y2=s[j][1];
x3=s[k][0];y3=s[k][1];
a=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
b=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
c=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
if(a*a+b*b>c*c&&a*a+c*c>b*b&&b*b+c*c>a*a)
time++;
}
}
}
printf("%d
",time);
}
return 0;
}
//问题如果不加sqrt会超时,这是什么原因。。加了就ac了