FZU 2110Star(计算几何)

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.0000000001
struct 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值