2015 Multi-University Training Contest 1 Hdu5295 unstable

来源:互联网 发布:华彩人生一点通 mac 编辑:程序博客网 时间:2024/05/29 02:15

Unstable

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 52    Accepted Submission(s): 16
Special Judge


Problem Description
Rasen had lost in labyrinth for 20 years. In a normal day, he found a bright screen. There were 4 points labeled by ‘A’ , ‘B’ , ‘C’ , ‘D’, and rasen could drag these point. And two points ‘E’ , ‘F’ moved. Rasen found that ‘E’ is the middle point of ‘A’ and ‘B’, and ‘F’ is the middle point of ‘C’ and ‘D’. Near the screen there was a marble slab.There were a list of the distance of AB , BC , CD , DA and EF. Rasen also found that the distance of these edge of the points in screen showed at the same time he drop the points. He wanted to know what will happen if the distances in screen are same with the number in slab.
 

Input
The first line of input contains only one integer T(<=50000), the number of test cases. 
Each case contains five float number, indicating the distance of AB , BC , CD , DA , EF.(0<=distance<=10000)
 

Output
For each test, first print a line “Case #i:”(without quotes),with i implying the case number, then output the coordinates of A,B,C,D four points. Answer will be considered as correct if the length got from your output (the spj will use double to get the point, and the distance from two points will calculate in the way of sqrt((x1-x2)^2 +(y1-y2)^2) ) and the length given is less than 10-4.
(It guarantees that there exists a solution. If there are many solutions, output any one of them.)
 

Sample Input
11.000000 1.000000 1.000000 1.000000 1.000000
 

Sample Output
Case #1:0.000000 0.0000001.000000 0.0000001.000000 1.0000000.000000 1.000000
 

Author
FZUACM
 

Source
2015 Multi-University Training Contest 1
 





#include<iostream>#include<cmath>#include<cstdio>using namespace std;#define eps 1e-5#define db double#define rt returnconst db pi = acos(-1.0);inline int sig(db x){rt (x>eps)-(x<-eps); }struct node{    db x,y;    node(db x_=0,db y_=0):x(x_),y(y_){}    void out(){printf("%.6lf %.6lf\n",x,y); }};node A,B,C,D,E,F;db ab,bc,cd,da,ef;db dist(node a,node b){rt sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); }db angle(db a,db b,db c){    cout<<"angle= "<<acos((a*a+b*b-c*c)/(2*a*b) )*180/pi<<endl;    rt acos((a*a+b*b-c*c)/(2*a*b)); }void print(){A.out();B.out();C.out();D.out(); }bool judge(db a,db b,db c){    cout<<"judge= "<<a<<" "<<b<<" "<<c<<endl;    if(a+b-c<=0)rt false;    if(a+c-b<=0)rt false;    if(b+c-a<=0)rt false;    rt true;}bool check(){    E.x=(A.x+B.x)/2; E.y=(A.y+B.y)/2;    F.x=(C.x+D.x)/2; F.y=(C.y+D.y)/2;    cout<<dist(A,B)<<" ?= "<<ab<<" "<<sig(dist(A,B)-ab)<<endl;    cout<<dist(B,C)<<" ?= "<<bc<<" "<<sig(dist(B,C)-bc)<<endl;    cout<<dist(C,D)<<" ?= "<<cd<<" "<<sig(dist(C,D)-cd)<<endl;    cout<<dist(D,A)<<" ?= "<<da<<" "<<sig(dist(D,A)-da)<<endl;    cout<<dist(E,F)<<" ?= "<<ef<<" "<<sig(dist(E,F)-ef)<<endl;    if(sig(dist(A,B)-ab)!=0)rt false;    if(sig(dist(B,C)-bc)!=0)rt false;    if(sig(dist(C,D)-cd)!=0)rt false;    if(sig(dist(D,A)-da)!=0)rt false;    if(sig(dist(E,F)-ef)!=0)rt false;    rt true;}int main(){    freopen("data1.in","r",stdin);//    freopen("data.out","w",stdout);    int T;scanf("%d",&T);    for(int t=1;t<=T;t++){        scanf("%lf%lf%lf%lf%lf",&ab,&bc,&cd,&da,&ef);        printf("%.6lf %.6lf %.6lf %.6lf %.6lf\n",ab,bc,cd,da,ef);        A.x=A.y=0;        B.x=ab ,B.y=0;        if(sig(bc+da-2*ef)==0){//不能构成第一个三角形==> AD //  BC            db cg=da-bc;            if(sig(cg)==0){//不能构成第二个三角形==>    DG //  AB                cout<<"$1"<<endl;                C.x=B.x , C.y=bc;                D.x=A.x , D.y=da;            }else{//能构成三角形,但是G可能在C的上面或下面                cout<<"$2"<<endl;                int ch=sig(cg);                cg=abs(cg);                db ang=angle(ab,cg,cd);                if(ch==-1)ang=pi-ang;                D.x=da*cos(ang);                D.y=da*sin(ang);                C.x=ab+bc*cos(ang);                C.y=bc*sin(ang);            }        }else{//能构成第一个三角形, AD 不平行 BC            db ang1=angle(bc,2*ef,da)+angle(da,2*ef,bc);            cout<<"ang1= "<<ang1*180/pi<<endl;            db cg = sqrt(bc*bc+da*da-2*bc*da*cos(ang1));            cout<<cd<<" "<<ab<<" "<<cg<<endl;            cout<<(cd*cd+ab*ab-cg*cg)<<" "<<(2*cd*ab)<<" "<<(cd*cd+ab*ab-cg*cg)/(2*cd*ab)<<endl;            db Jang=angle(cd,ab,cg);            cout<<"Jang= "<<Jang<<" "<<acos(-1)*180/pi<<endl;            cout<<"cg= "<<cg<<endl;            if(sig(Jang)==0){//不能构成第二个三角形,c d g 共线, DG//CG//CD//AB                cout<<"$3"<<endl;                db ang2=angle(da,cg,bc);                cout<<da<<" "<<cg<<" "<<bc<<endl;                cout<<"ang2= "<<ang2*180/pi<<endl;                D.x=da*cos(ang2);                D.y=da*sin(ang2);                C.x=ab+bc*cos(ang2);                C.y=   bc*sin(ang2);                cout<<endl;print();cout<<endl;                if(check()==false){                    cout<<"$4"<<endl;                    D.x=da*cos(pi-ang2);                    D.y=da*sin(pi-ang2);                    C.x=ab+bc*cos(pi-ang1-ang2);                    C.y=   bc*sin(pi-ang1-ang2);                    cout<<endl;print();cout<<endl;                }            }else{//能构成第二个三角形                cout<<"$5"<<endl;                db ang2=angle(da,cg,bc)+angle(ab,cg,cd);                D.x=da*cos(ang2);                D.y=da*sin(ang2);                C.x=ab+bc*cos(ang1+ang2);                C.y=   bc*sin(ang1+ang2);                if(check()==false){                    cout<<"$6"<<endl;                    ang2=angle(da,cg,bc)-angle(ab,cg,cd);                    D.x=da*cos(ang2);                    D.y=da*sin(ang2);                    C.x=ab+bc*cos(ang1+ang2);                    C.y=   bc*sin(ang1+ang2);                    if(check()==false){                        cout<<"$7"<<endl;                        ang2=angle(ab,cg,cd)-angle(da,cg,bc);                        D.x=da*cos(ang2);                        D.y=da*sin(ang2);                        C.x=ab+bc*cos(ang2-ang1);                        C.y=   bc*sin(ang2-ang1);                        if(check()==false){                            cout<<"$8"<<endl;                            ang2=2*pi-angle(ab,cg,cd)-angle(da,cg,bc);                            D.x=da*cos(ang2);                            D.y=da*sin(ang2);                            C.x=ab+bc*cos(ang2-ang1);                            C.y=   bc*sin(ang2-ang1);                        }                    }                }            }        }        if(check()==false)            printf("%.6lf %.6lf %.6lf %.6lf %.6lf\n",ab,bc,cd,da,ef);        printf("Case #%d:\n",t);        print();    }    rt 0;}/*******************************************卡死两组数据上!!!39.869227 74.690823 82.892752 48.073310 13.313721   50.062572 77.061618 25.220247 61.188485 68.461497********************************************/


// 用圆写#include<iostream>#include<cmath>#include<cstdio>using namespace std;#define eps 1e-6#define db doubleinline int sig(db x){return (x>eps)-(x<-eps); }struct node{    db x,y;    node(db x_=0,db y_=0):x(x_),y(y_){}    void reset(db x_=0,db y_=0){x=x_,y=y_;}    node operator + (node a){return node(x+a.x,y+a.y); }    node operator - (node a){return node(x-a.x,y-a.y); }    node operator * (db a){return node(x*a,y*a); }    db operator * (node a){return x*a.x+y*a.y; }    db operator ^ (node a){return x*a.y-a.x*y; }    db dis(){return sqrt(x*x+y*y); }    db dis2(){return (x*x+y*y); }    node T(){return node(-y,x); }    void out(){printf("%.6lf %.6lf\n",x,y); }};struct CCL{    node o;    db r;    CCL(){}    CCL(node o_,db r_):o(o_),r(r_){}    int cp_L(node a,node b,node p[]){        db A=(a-b).dis2(),B=-2.*((o-a)*(b-a)),C=(a-o).dis2()-r*r,D=B*B-4.*A*C;        if(sig(D)<0)return 0;        D=fabs(D);        db u1=(-B-sqrt(D))/(2.*A),u2=(-B+sqrt(D))/(2.*A);        p[0]=a+(b-a)*u1;        p[1]=a+(b-a)*u2;        return sig(D)+1;    }    int cp_ccl(CCL c,node p[]){        db d=(o-c.o).dis2();        if(sig(sqrt(fabs(d))+min(r,c.r)-max(r,c.r))<0||sig(d)==0)return 0;        db u = (r*r-c.r*c.r)/(d+d)+0.5;        node a=o+(c.o-o)*u,b=a+(c.o-o).T();        return cp_L(a,b,p);    }};db ab,bc,cd,da,ef;node A,B,C,D,E,F;void solve(){    B.reset(bc,0);    C.reset(0,0);    node p[2];    CCL O1(B,2*ef),O2(C,da);    O1.cp_ccl(O2,p);    node A2=p[0];    node G=B-C+A2;    CCL O3(C,cd),O4(G,ab);    O3.cp_ccl(O4,p);    D=p[0];    A=D+C-A2;}int main(){    freopen("5295.in","r",stdin);//    freopen("5295.out","w",stdout);    int T;scanf("%d",&T);    for(int ca=1;ca<=T;ca++){        scanf("%lf%lf%lf%lf%lf",&ab,&bc,&cd,&da,&ef);        solve();        printf("Case #%d:\n",ca);        A.out(),B.out(),C.out(),D.out();    }    return 0;}
//还是卡死在那几组数据上,精度问题的数据!!!!!!!!

换个姿势~~~~~~,换个求圆交
#include<iostream>#include<cstdio>#include<cmath>using namespace std;#define db doubleconst db eps = 1e-6;inline int sig(db x){return (x>eps)-(x<-eps); }struct node{    db x,y;    node(db a=0,db b=0):x(a),y(b){}    void set(db a,db b){x=a,y=b; }    void out(){printf("%.6lf %.6lf\n",x,y); }    node operator + (node a){return node(x+a.x,y+a.y); }    node operator - (node a){return node(x-a.x,y-a.y); }    node operator / (db a){return node(x/a,y/a); }    bool operator == (const node &a)const{        return sig(x-a.x)==0&&sig(y-a.y)==0;    }    db dis2(){return x*x+y*y; }    db dis(){return sqrt(dis2()); }};db dist(node a,node b){return (a-b).dis(); }struct Cir{    node o;    db r;    Cir(){}    Cir(node o_,db r_){ o=o_ , r=r_;  }    void set(node o_,db r_){o=o_ , r=r_; }    bool operator == (const Cir &a)const{        return o==a.o && sig(r-a.r)==0;    }};void c2point(Cir c1,Cir c2,node &rp1,node &rp2){    if(c1==c2){        rp1=c1.o+node(0,c1.r);        rp2=c1.o-node(0,c1.r);        return ;    }    node p1=c1.o , p2=c2.o;    db r1=c1.r , r2=c2.r;    db a=p2.x-p1.x , b=p2.y-p1.y;    db r=(a*a+b*b+r1*r1-r2*r2)/2;    db tmp;    if(a==0&&b!=0){        rp1.y=rp2.y=r/b;        tmp = r1*r1-rp1.y*rp1.y;        if(sig(tmp)<=0)tmp=0;        rp1.x=sqrt(tmp);        rp2.x=-rp1.x;    }else if(a!=0 && b==0){        rp1.x=rp2.x=r/a;        tmp=r1*r1-rp1.x*rp1.x;        if(sig(tmp)<=0)tmp=0;        rp1.y=sqrt(tmp);        rp2.y=-rp1.y;    }else if(a!=0&&b!=0){        tmp=b*b*r*r-(a*a+b*b)*(r*r-r1*r1*a*a);        if(sig(tmp)<=0)tmp=0;        rp1.y=(b*r+sqrt(tmp))/(a*a+b*b);        rp2.y=(b*r-sqrt(tmp))/(a*a+b*b);        rp1.x=(r-b*rp1.y)/a;        rp2.x=(r-b*rp2.y)/a;}else{//两圆无解,a==0 b==0圆点重合,且半径不一样    }}db ab,bc,cd,da,ef;node A,B,C,D,A2,G;void graph_construct(){    C.set(0,0);    B.set(bc,0);    Cir O1(C,da),O2(B,2*ef);    node p;    c2point(O1,O2,A2,p);    G = A2+(B-C);    O1.set(C,cd),O2.set(G,ab);    c2point(O1,O2,D,p);    A=D+(C-A2);}int main(){    int T;scanf("%d",&T);    for(int ca=1;ca<=T;ca++){        scanf("%lf%lf%lf%lf%lf",&ab,&bc,&cd,&da,&ef);        graph_construct();        printf("Case #%d:\n",ca);        A.out();B.out();C.out();D.out();    }    return 0;}




0 0
原创粉丝点击