您的位置:首页 > 其它

FZU-2110-Star

2016-03-25 12:08 351 查看
I - Star

Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u

Submit

Status

Practice

FZU 2110

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

题意,第一行给出T,然后T组数据,每组数据第一行给出n,接下来n行给出n组坐标,输出这n个点能构成的锐角三角形个数。

思路:通过坐标得到三边大小,然后判断锐角三角形任意两边平方和大于第三边平方。

三层for循环暴力枚举即可

代码

#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<string.h>
#include<stdio.h>
#include<queue>
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;//n组数据
scanf("%d",&n);
double num[2][105];//存储坐标
for(int i=0; i<n; i++)
scanf("%lf%lf",&num[0][i],&num[1][i]);//存储x,y坐标
double a,b,c;//三角形三条边
int sum=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++)
{
a=sqrt((num[0][i]-num[0][j])*(num[0][i]-num[0][j])+(num[1][i]-num[1][j])*(num[1][i]-num[1][j]));
b=sqrt((num[0][i]-num[0][k])*(num[0][i]-num[0][k])+(num[1][i]-num[1][k])*(num[1][i]-num[1][k]));
c=sqrt((num[0][k]-num[0][j])*(num[0][k]-num[0][j])+(num[1][k]-num[1][j])*(num[1][k]-num[1][j]));
if(a*a+b*b>c*c&&a*a+c*c>b*b&&b*b+c*c>a*a)
sum++;
}
printf("%d\n",sum);
}
return 0;
}


注意数据精度
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: