FZOJ2110: Star
Problem Description
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 <string.h> #include <math.h> int main() { double a[2][105],x,y,z; int i,j,k,ans,n,t,flag1,flag2,flag3; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i = 0;i<n;i++) scanf("%lf%lf",&a[0][i],&a[1][i]); ans = 0; for(i = 0;i<n-2;i++) { for(j = i+1;j<n-1;j++) { for(k = j+1;k<n;k++) { flag1 = flag2 = flag3 = 0; x = sqrt((a[0][i]-a[0][j])*(a[0][i]-a[0][j])+(a[1][i]-a[1][j])*(a[1][i]-a[1][j])); y = sqrt((a[0][i]-a[0][k])*(a[0][i]-a[0][k])+(a[1][i]-a[1][k])*(a[1][i]-a[1][k])); z = sqrt((a[0][k]-a[0][j])*(a[0][k]-a[0][j])+(a[1][k]-a[1][j])*(a[1][k]-a[1][j])); if(x*x+y*y>z*z) flag1 = 1; if(y*y+z*z>x*x) flag2 = 1; if(x*x+z*z>y*y) flag3 = 1; if(flag1 && flag2 && flag3) ans++; } } } printf("%d\n",ans); } return 0; }