Fzoj--2110--Stra(数学几何)


                                                  Problem 2110 Star

Accept: 864    Submit: 2571
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 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

 Source

“高教社杯”第三届福建省大学生程序设计竞赛

题意:平面上有n个星星,求有多少个锐角三角形

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
	double x,y;
}p[10100];
int cmp(node s1,node s2)
{
	return s1.x<s2.x;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		scanf("%lf%lf",&p[i].x,&p[i].y);
		sort(p,p+n,cmp);
		if(n<3) 
		{
			printf("0\n");
			continue;
		}
		int ans=0;
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				for(int k=j+1;k<n;k++)
				{
					int f1=0,f2=0,f3=0;
					double a=sqrt((p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y));
					double b=sqrt((p[i].x-p[k].x)*(p[i].x-p[k].x)+(p[i].y-p[k].y)*(p[i].y-p[k].y));
					double c=sqrt((p[j].x-p[k].x)*(p[j].x-p[k].x)+(p[j].y-p[k].y)*(p[j].y-p[k].y));
					if(a*a+b*b>c*c)
					f1=1;
					if(a*a+c*c>b*b)
					f2=1;
					if(b*b+c*c>a*a)
					f3=1;
					if(f1&&f2&&f3)
					ans++;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


你可能感兴趣的:(Fzoj--2110--Stra(数学几何))