zoukankan      html  css  js  c++  java
  • ACM Changchun 2015-E Rebuild

    Rebuild

    https://blog.csdn.net/LuRiCheng/article/details/70135430

    自己懒得写,转载的别人的解释挺好很详细

    /**
     * ============================
     * @title:    changcun 2015 PE
     * @Author:   kuroko
     * @Version:  1.0 
     * @DateTime: 2018-08-31 09:31:59
     * ============================
     */
    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e4+10;
    const double pi =acos(-1.0);
    const double eps=1e-6;
    int n,x[maxn],y[maxn];
    double d[maxn],r[maxn];
    int sgn(double t)
    {
        return (t>eps)-(t<-eps);
    }
    double f(double a, double b, double c, double t)
    {
        return a*t*t + b*t + c;
    }
    void input()
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%d%d",&x[i],&y[i]);
    }
    void solve()
    {
        x[n]=x[0];
        y[n]=y[0];
        for(int i=0;i<n;i++)
            d[i]=sqrt((x[i+1]-x[i])*(x[i+1]-x[i])+(y[i+1]-y[i])*(y[i+1]-y[i]));
        if(n&1)//奇数
        {
            double all=0,other=0,ans=0;
            for(int i=0;i<n;i++)
            {
                all+=d[i];
                if(i&1)
                  other+=d[i];
            }
            r[0]=all/2-other;
            if(sgn(r[0])<0)
            {
                printf("IMPOSSIBLE
    ");
                return;
            }
            ans+=r[0]*r[0];
            for(int i=1;i<n;i++)
            {
                r[i]=d[i-1]-r[i-1];
                if(sgn(r[i])<0)
                {
                    printf("IMPOSSIBLE
    ");
                    return;
                }
                ans+=r[i]*r[i];
            }
            printf("%.2lf
    ",pi*ans);
            for(int i=0;i<n;i++)
                printf("%.2lf
    ",r[i]);
        }
        else
        {
            double temp=0;
            for(int i=0;i<n;i+=2)
                temp+=d[i]-d[i+1];
            if(sgn(temp)!=0)
            {
                printf("IMPOSSIBLE
    ");
                return ;
            }
            int k=1;
            double b=0,L=0,R=d[0];
            double A=1,B=0,C=0;
            //计算的是ri=b+k*r0(k=1或-1)
            for(int i=1;i<n;i++)
            {
                k=-k;
                b=-b+d[i-1];
                if(k==1)
                    L=max(L,-b);
                else//减去的时候
                    R=min(R,b);
                A++;
                B+=2*k*b;
                C+=b*b;
            }
            if(sgn(L-R)>0)
            {
                printf("IMPOSSIBLE
    ");
                return;
            }
            double mid=-B/(2*A),ans;
            if(sgn(L-mid)>=0)
            {
                ans=f(A,B,C,L);
                r[0]=L;
            }
            if(sgn(R-mid)<=0)
            {
                ans=f(A,B,C,R);
                r[0]=R;
            }
            if(sgn(mid-L)>=0&&sgn(mid-R)<=0)
            {
                ans=f(A,B,C,mid);
                r[0]=mid;
            }
            printf("%.2f
    ",pi*ans); 
            for(int i=0;i<n;i++)
            {
                if(i)
                    r[i]=d[i-1]-r[i-1];
                printf("%.2lf
    ",r[i]);
            }
        }
    }
    int main(int argc, char const *argv[])
    {
        freopen("in.txt","r",stdin);
        int T;
        scanf("%d",&T);
        while(T--)
        {
            input();
            solve();
        }
        return 0;
    }
    View Code
  • 相关阅读:
    最终一致性解决实例
    分布式事务一致性方案
    分布式事务
    OSX
    JAVA
    Eclipse
    Activiti
    CentOS
    用Visual Studio 2015 编写 MASM 汇编程序(二)从头开发一个Win32汇编程序
    Oracle
  • 原文地址:https://www.cnblogs.com/kuroko-ghh/p/9567411.html
Copyright © 2011-2022 走看看