FZU 2110Star(计算几何)

来源:互联网 发布:苹果mac怎么删除照片 编辑:程序博客网 时间:2024/05/16 11:37

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

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

Submit Back Status Discuss

本题是一道简单的计算几何题目,
题目的意思是:让你求出由n个点可以组成锐角三角形的个数。
题目给出的点的个数为100,所以直接暴力就可以了。

判断锐角三角形的方法:两个较短边的平方和大于较长那条边的平方和,这个三角形就是锐角三角形。

下面是AC代码:
有一点想不明白,为什么题目中给出的点的坐标是整数,但是long long 根本过不了,最后用double过的这道题。。

#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;#define ee 0.0000000001struct dian{    double x,y;} point[102];double dis(double x1,double x2,double y1,double y2){    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);}double judge(double x,double y,double z){    if(x+y+ee>z)    {        return 0;    }    return 1;}int main(){    int t;    scanf("%d",&t);    while(t--)    {        int n;        scanf("%d",&n);        double distant[3];        int i,j,k,sum=0;        for(i = 0; i < n; i++)        {            scanf("%lf%lf",&point[i].x,&point[i].y);        }        for(i = 0; i < n-2; i++)            for(j = i+1; j < n-1; j++)                for(k = j+1; k < n; k++)                {                    distant[0]=dis(point[i].x,point[j].x,point[i].y,point[j].y);                    distant[1]=dis(point[i].x,point[k].x,point[i].y,point[k].y);                    distant[2]=dis(point[j].x,point[k].x,point[j].y,point[k].y);                    sort(distant,distant+3);                    if(judge(distant[0],distant[1],distant[2])==0)                    {                        sum++;                    }                }        printf("%d\n",sum);    }    return 0;}
0 0