zoukankan      html  css  js  c++  java
  • BZOJ 2508 简单题/BZOJ 3775 点和直线

    求下偏导就好了。。。。直接O(1)维护。

    #include<iostream>
    #include<cstring>
    #include<cstdio> 
    #include<algorithm>
    #include<cmath>
    #define eps 1e-7
    #define maxn 120050
    using namespace std;
    double a=0,b=0,c=0,d=0,e=0,f=0;
    double x11,y11,x22,y22;
    double tab[10];
    int n,type,k,cnt=0,tot=0;
    struct line
    {
        double a,b,c;
        line (double a,double b,double c):a(a),b(b),c(c) {}
        line () {}
    }p[maxn];
    int main()
    {
        scanf("%d",&n);
        for (int i=1;i<=n;i++)
        {
            scanf("%d",&type);
            if (type==0)
            {
                scanf("%lf%lf%lf%lf",&x11,&y11,&x22,&y22);
                if (x11==x22) p[++cnt]=line(1,0,-x11);
                else if (y11==y22) p[++cnt]=line(0,1,-y11);
                else p[++cnt]=line(y22-y11,x11-x22,-x11*y22+x11*y11+x22*y11-x11*y11);
                double a1=p[cnt].a,b1=p[cnt].b,c1=p[cnt].c,dd=a1*a1+b1*b1;
                a+=a1*a1/dd;b+=a1*b1/dd;c+=a1*c1/dd;
                d+=a1*b1/dd;e+=b1*b1/dd;f+=b1*c1/dd;
                tab[1]+=a1*a1/dd;tab[2]+=b1*b1/dd;tab[3]+=c1*c1/dd;
                tab[4]+=2.0*a1*b1/dd;tab[5]+=2.0*a1*c1/dd;tab[6]+=2.0*b1*c1/dd;
                tot++;
            }
            else if (type==1)
            {
                scanf("%d",&k);tot--;
                double a1=p[k].a,b1=p[k].b,c1=p[k].c,dd=a1*a1+b1*b1;
                a-=a1*a1/dd;b-=a1*b1/dd;c-=a1*c1/dd;
                d-=a1*b1/dd;e-=b1*b1/dd;f-=b1*c1/dd;
                tab[1]-=a1*a1/dd;tab[2]-=b1*b1/dd;tab[3]-=c1*c1/dd;
                tab[4]-=2.0*a1*b1/dd;tab[5]-=2.0*a1*c1/dd;tab[6]-=2.0*b1*c1/dd;
            }
            else
            {
                if (tot==1) {printf("0.00
    ");continue;}
                double x,y;
                if (a*e==b*d)
                {
                    x=0;
                    if (fabs(b)>eps) y=-c/b;
                    else if (fabs(e)>eps) y=-(f/e);
                    else y=0;
                    double ans=tab[1]*x*x+tab[2]*y*y+tab[3]+tab[4]*x*y+tab[5]*x+tab[6]*y;
                    y=0;
                    if (fabs(a)>eps) x=-(c/a);
                    else if (fabs(d)>eps) x=-(f/d);
                    else x=0;
                    ans=min(ans,tab[1]*x*x+tab[2]*y*y+tab[3]+tab[4]*x*y+tab[5]*x+tab[6]*y);
                    printf("%.2f
    ",ans);continue;
                }
                else {y=(a*f-c*d)/(b*d-a*e);x=(b*f-c*e)/(a*e-b*d);}
                double ans=tab[1]*x*x+tab[2]*y*y+tab[3]+tab[4]*x*y+tab[5]*x+tab[6]*y;
                if (fabs(ans)<1e-3) printf("0.00
    ");else printf("%.2f
    ",ans);
            }
        }
        return 0;
    }
  • 相关阅读:
    考拉兹猜想,100万以内的数
    给任意a、b、c三个数作为边盘都是否能构成三角形
    计数算法-对200万考生的成绩就行排序
    冒泡排序
    插入排序
    Echarts
    vue+tinymce
    java RestTemplate.postForObject请求传参
    java计算今天起后7天时间 +昨天八点+今天前7天的日期
    layui+echarts+动态数据
  • 原文地址:https://www.cnblogs.com/ziliuziliu/p/6485663.html
Copyright © 2011-2022 走看看