zoukankan      html  css  js  c++  java
  • 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
    ",ans);
        return 0;
    }
    Ruminations on Ruminants
  • 相关阅读:
    2017.1.16【初中部 】普及组模拟赛C组总结
    用Redis实现分布式锁 与 实现任务队列
    Mysql+Keepalived双主热备高可用操作记录
    Linux下防御DDOS攻击的操作梳理
    真正的ddos防御之道,简单干脆有效!
    ip黑白名单防火墙frdev的原理与实现
    一种简单的处理大流量访问的方法
    PHP解决网站大流量与高并发
    PHP反射机制实现自动依赖注入
    nginx 根据域名和地址跳转
  • 原文地址:https://www.cnblogs.com/JDFZ-ZZ/p/14264352.html
Copyright © 2011-2022 走看看