FZU OJ 2110 Star (计算几何)

本文介绍了一种算法,用于计算平面上多个点能够组成的锐角三角形的数量。通过三重循环遍历所有可能的点组合,并应用锐角三角形的判断条件来统计总数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem 2110 Star

Accept: 585    Submit: 1731
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

130 010 05 1000

 Sample Output

1

 Source

题意:给你一些点,计算这些点能组成多少个锐角三角形。
锐角三角形计算公式:a*a+b*b>c*c (两边之间的距离大于第三边)
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef struct Point
{
    double x,y;
}Point;
Point point[160];
int main()
{
    int ans, t, i, j, k, n;
    double a,b,c;
    cin >> t;
    while (t--)
    {
        cin >> n;
        for (i=0; i<n; i++)
        {
            cin >> point[i].x >> point[i].y;
        }
        ans = 0;
        for (i=0; i<n-2; i++)//利用三重循环每次计算三个点之间的关系
        {
            for (j=i+1; j<n-1; j++)
            {
                for (k=j+1; k<n; k++)
                {
                    a = (point[i].x-point[j].x)*(point[i].x-point[j].x) + (point[i].y-point[j].y)*(point[i].y-point[j].y);//计算两点之间的距离
                    b = (point[i].x-point[k].x)*(point[i].x-point[k].x) + (point[i].y-point[k].y)*(point[i].y-point[k].y);
                    c = (point[k].x-point[j].x)*(point[k].x-point[j].x) + (point[k].y-point[j].y)*(point[k].y-point[j].y);

                    if (a+b>c && a+c>b && c+b>a) //三点都满足才是锐角三角形
                    {
                        ans++;
                    }

                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值