QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#408871#6763. Triangle Pendantping222WA 2ms4004kbC++174.5kb2024-05-11 10:06:222024-05-11 10:06:23

Judging History

你现在查看的是最新测评结果

  • [2024-05-11 10:06:23]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4004kb
  • [2024-05-11 10:06:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

struct dot
{
    double x;
    double y;
    double z;
};

struct vect
{
    double x;
    double y;
    double z;
};

double abs_vect(vect v)
//向量的模
{
    return sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
}

double dis(dot a,dot b)
//两点距离
{
    vect t;
    t.x=a.x-b.x;
    t.y=a.y-b.y;
    t.z=a.z-b.z;
    return abs_vect(t);
}

double p_vect(vect v1,vect v2)
//向量点积
{
    return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z;
}

double count(dot D,dot A,vect DE)
//计算向量DA在向量HE上的投影长度
{
    vect DA;
    DA.x=A.x-D.x;
    DA.y=A.y-D.y;
    DA.z=A.z-D.z;
    if (abs_vect(DE)>-1e-10 && abs_vect(DE)<1e-10)
        return 0;
    return p_vect(DA,DE)/abs_vect(DE);
}

bool check(int a,int b,int c)
//三角形判定
{
    if (a+b<=c || a+c<=b || b+c<=a)
        return false;
    return true;
}

void count2(int len_AD,int len_BD,dot &A,dot &B,dot &C,dot &D)
//两条线(AD,BD)绷直,求D点坐标
{
    double a=len_BD,b=len_AD,c=dis(A,B);
    dot A_,B_,C_;
    A_.x=0; A_.y=0;
    B_.x=c; B_.y=0;
    C_.x=(double)(a*a-b*b-c*c)/(-2*c);
    C_.y=sqrt(b*b-C_.x*C_.x);
    if ((B.x-A.x)*(C.y-A.y)-(B.y-A.y)*(C.x-A.x)>0)
        C_.y*=-1;

    double rot_a=B.x-A.x,rot_b=B.y-A.y; //旋转向量
    double len=sqrt(rot_a*rot_a+rot_b*rot_b);
    rot_a=rot_a/len;
    rot_b=rot_b/len;

    D.x=A.x+(C_.x*rot_a-C_.y*rot_b);
    D.y=A.y+(C_.x*rot_b+C_.y*rot_a);
    D.z=0;
}

void count1(int len_AD,dot &A,dot &B,dot &C,dot &D,dot &E,double &ha,double &hb,double &hc)
//一条线(AD)绷直,直接求结果
{
    vect AE;
    AE.x=E.x-A.x;
    AE.y=E.y-A.y;
    AE.z=E.z-A.z;
    
    double len=abs_vect(AE);
    double m=len_AD/len;

    AE.x*=m;
    AE.y*=m;
    AE.z*=m;

    D.x=A.x-AE.x;
    D.y=A.y-AE.y;
    D.z=0;

    /*
    ha=len_AD;
    hb=len_AD+count(A,B,AE);
    hc=len_AD+count(A,C,AE);
    */
}

void s_count(int len_AD,int len_BD,int len_CD,dot &A,dot &B,dot &C,dot &D,dot &E,double &ha,double &hb,double &hc)
//不可构成三棱锥,且AD是最短边时,求解
{
    count1(len_AD,A,B,C,D,E,ha,hb,hc);

    if (len_BD<len_CD)
        if (dis(B,D)>len_BD)
            count2(len_AD,len_BD,A,B,C,D);
        else if (dis(C,D)>len_CD)
            count2(len_AD,len_CD,A,C,B,D);
    else
        if (dis(C,D)>len_CD)
            count2(len_AD,len_CD,A,C,B,D);
        else if (dis(B,D)>len_BD)
            count2(len_AD,len_BD,A,B,C,D);
    
    vect DE;
    DE.x=E.x-D.x;
    DE.y=E.y-D.y;
    DE.z=E.z-D.z;

    ha=count(D,A,DE);
    hb=count(D,B,DE);
    hc=count(D,C,DE);
    return;
}

void solve()
{
    int x,y,z,a,b,c;
    double ha,hb,hc;
    cin >> x >> y >> z >> a >> b >> c;

    dot A,B,C,D,E;
    A.x=0; A.y=0;
    B.x=c; B.y=0;
    C.x=(double)(a*a-b*b-c*c)/(-2*c);
    C.y=sqrt(b*b-C.x*C.x);
    A.z=B.z=C.z=0;
    
    E.x=(A.x+B.x+C.x)/3.0;
    E.y=(A.y+B.y+C.y)/3.0;
    E.z=0;

    bool check_a=check(y,z,a);
    bool check_b=check(x,z,b);
    bool check_c=check(x,y,c);
    bool check=(check_a+check_b+check_c==3);
    if (!check_a && check_b && check_c && y+z==a) check=1;
    if (!check_b && check_a && check_c && x+z==b) check=1;
    if (!check_c && check_b && check_a && y+x==c) check=1;

    D.x=(double)(y*y-x*x-c*c)/(-2*c);
    D.y=(double)(z*z-x*x-(C.x)*(C.x)-(C.y)*(C.y)+2*C.x*D.x)/(-2*C.y);
    D.z=x*x-(D.x)*(D.x)-(D.y)*(D.y);
    if (fabs(D.z)<1e-10)
        D.z=0;

    //if (check)   //可构成三棱锥
    if (D.z>-1e-10)
    {
        D.z=sqrt(D.z);

        vect DE;
        DE.x=E.x-D.x;
        DE.y=E.y-D.y;
        DE.z=E.z-D.z;

        ha=count(D,A,DE);
        hb=count(D,B,DE);
        hc=count(D,C,DE);
    }
    else    //不可构成三棱锥时,依照最短边求解
    {
        if (x<=y && x<=z)
            s_count(x,y,z,A,B,C,D,E,ha,hb,hc);
        else if (y<=x && y<=z)
            s_count(y,x,z,B,A,C,D,E,hb,ha,hc);
        else if (z<=x && z<=y)
            s_count(z,y,x,C,B,A,D,E,hc,hb,ha);
    }

    ha*=-1;
    hb*=-1;
    hc*=-1;
    printf("%.15lf %.15lf %.15lf\n",ha,hb,hc);
    /*
    printf("%lf %lf %lf\n",A.x,A.y,A.z);
    printf("%lf %lf %lf\n",B.x,B.y,B.z);
    printf("%lf %lf %lf\n",C.x,C.y,C.z);
    printf("%lf %lf %lf\n",D.x,D.y,D.z);
    printf("%lf %lf %lf\n",E.x,E.y,E.z);
    */
    
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t; cin >> t;
    for (;t;t--)
        solve();
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3936kb

input:

2
1 1 1 1 1 1
2 3 3 1 1 1

output:

-0.816496580927726 -0.816496580927726 -0.816496580927726
-2.000000000000000 -2.866025403784439 -2.866025403784439

result:

ok 6 numbers

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 4004kb

input:

1000
21 2 14 12 13 4
29 19 13 15 10 17
29 24 15 29 24 23
29 17 30 18 9 25
27 24 30 16 4 15
28 13 17 12 21 16
16 22 10 22 15 8
15 23 24 23 27 13
26 3 27 15 16 17
5 8 20 17 6 12
24 14 13 15 19 13
27 22 18 18 23 30
22 18 14 11 29 28
7 13 22 22 17 11
19 9 16 22 20 17
21 14 20 6 29 25
20 10 19 9 27 27
17...

output:

-2.935856727586833 -2.000000000000000 -13.352348999857673
-22.146476218003027 -16.076204705476879 -12.241826659011300
-28.027431433359670 -18.318582636182793 -8.243362186282258
-27.266119651334364 -13.159319584325651 -26.882525397692710
-26.534933366925671 -22.066632132649342 -29.616079568529663
-26...

result:

wrong answer 46th numbers differ - expected: '-11.14286', found: '-38.39390', error = '2.44561'