CF603D Ruminations on Ruminants

Description

Kevin Sun is ruminating on the origin of cows while standing at the origin of the Cartesian plane. He notices $ n $ lines $ l_1 , l_2 , \cdots ,l_n$ on the plane, each representable by an equation of the form $ ax+by=c $ . He also observes that no two lines are parallel and that no three lines pass through the same point.

For each triple $ (i,j,k) $ such that $ 1 \leq i < j < k \leq n $ , Kevin considers the triangle formed by the three lines $l_i , l_j , l_k$ . He calls a triangle original if the circumcircle of that triangle passes through the origin. Since Kevin believes that the circles of bovine life are tied directly to such triangles, he wants to know the number of original triangles formed by unordered triples of distinct lines.

Recall that the circumcircle of a triangle is the circle which passes through all the vertices of that triangle.

Solution

考虑西姆森定理:若一点在三角形三边所在直线上的射影共线,则该点在此三角形的外接圆上

枚举原点在每一条轴线上的投影,计算其与其它点的斜率,与其同斜率的点中任意选两个就可以组成符合要求的三角形

重合的点需要特判

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n;
double x[2005],y[2005],k[2005];
const double eps=1e-12;
long long ans;
inline int read(){
    int w=0,f=1;
    char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9')w=(w<<1)+(w<<3)+ch-'0',ch=getchar();
    return w*f;
}
int main(){
    n=read();
    for(int i=1;i<=n;i++){
        double a=read(),b=read(),c=read();
        x[i]=a*c/(a*a+b*b),y[i]=b*c/(a*a+b*b);
    }
    for(int i=1;i<=n-2;i++){
        int tot=0,sum=0,pos=1;
        for(int j=i+1;j<=n;j++)
            if(x[i]==x[j]&&y[i]==y[j])++sum;
            else if(x[i]!=x[j])k[++tot]=(y[j]-y[i])/(x[j]-x[i]);
            else k[++tot]=1e9;
        sort(k+1,k+tot+1);
        for(int j=1;j<=sum;j++)ans+=n-i-j;
        for(int j=1;j<=tot;j++){
            while(abs(k[pos]-k[j])>eps)++pos;
            ans+=j-pos;
        }
    }
    printf("%I64d\n",ans);
    return 0;
}
Ruminations on Ruminants

 

posted @ 2021-01-12 15:05  QDK_Storm  阅读(143)  评论(0编辑  收藏  举报