ACM Changchun 2015-E Rebuild
阿新 • • 發佈:2018-08-31
build eps tle bsp chang using namespace bit tps
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 namespaceView Codestd; 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\n"); 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\n"); return; } ans+=r[i]*r[i]; } printf("%.2lf\n",pi*ans); for(int i=0;i<n;i++) printf("%.2lf\n",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\n"); 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\n"); 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\n",pi*ans); for(int i=0;i<n;i++) { if(i) r[i]=d[i-1]-r[i-1]; printf("%.2lf\n",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; }
ACM Changchun 2015-E Rebuild