FZU 2110 Star(计算几何)

题目:http://acm.fzu.edu.cn/problem.php?pid=2110

代码:

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define eps 1e-9

using namespace std;

struct node
{
    double x,y;                                          //用double
} q[120];

double dis(node a,node b)
{
    double disx=(a.x-b.x)*(a.x-b.x);
    double disy=(a.y-b.y)*(a.y-b.y);

    double ans=disx+disy;
    return ans;
}

int main()
{
    int t;
    scanf("%d",&t);

    while(t--)
    {
        int n;
        scanf("%d",&n);

        for(int i=0; i<n; i++)
        {
            scanf("%lf%lf",&q[i].x,&q[i].y);
        }
        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)
                {
                    double num[3];
                    num[0] = dis(q[i], q[j]);
                    num[1] = dis(q[i], q[k]);
                    num[2] = dis(q[j], q[k]);
                    sort(num, num+3);                             //找出边的顺序。
                    if (num[0] + num[1] + eps > num[2])//||num[0]+num[2]+eps>num[1]||num[1]+num[2]+eps>num[0])
                    {
                        ans++;                             //钝角三角形时不满足
                    }
                }
            }
        }

        printf("%d\n",ans);
    }
    return 0;
}


你可能感兴趣的:(FZU 2110 Star(计算几何))