I wrote a program, but I got WA. Maybe there are some problems with presision.
Could anybody tell me the trick?
Re: I wrote a program, but I got WA. Maybe there are some problems with presision.
> Could anybody tell me the trick?
writeln (answer:10:2)
Re: I wrote a program, but I got WA. Maybe there are some problems with presision.
> > Could anybody tell me the trick?
>
> writeln (answer:10:2)
I know that. But there are some other problems...
Here's my code:
#include <stdio.h>
#include <math.h>
typedef struct TPoint {
long double X, Y, Z;
} TPoint;
const long double Eps = 1e-50;
TPoint A, B, O;
long double R, Phi, CosPhi, L, AO, BO, AB, H;
long double Sqr (long double X) {
return X * X;
}
long double Dist (TPoint A, TPoint B) {
return sqrtl (Sqr (A.X - B.X) + Sqr (A.Y - B.Y) + Sqr (A.Z - B.Z));
}
int main () {
scanf ("%Lf%Lf%Lf", &(A.X), &(A.Y), &(A.Z));
scanf ("%Lf%Lf%Lf", &(B.X), &(B.Y), &(B.Z));
scanf ("%Lf%Lf%Lf", &(O.X), &(O.Y), &(O.Z));
scanf ("%Lf", &R);
AO = Dist (A, O);
BO = Dist (B, O);
AB = Dist (A, B);
if (AB < Eps) {
printf ("0.00\n");
return 0;
}
CosPhi = ((A.X - O.X) * (B.X - O.X) + (A.Y - O.Y) * (B.Y - O.Y) +
(A.Z - O.Z) * (B.Z - O.Z))
/ (AO * BO);
Phi = acosl (CosPhi);
H = AO * BO * sqrtl (1 - Sqr(CosPhi)) / AB;
if (H < R - Eps) {
Phi -= acosl (R / AO) + acosl (R / BO);
if (Phi < 0) Phi = 0;
L = sqrtl (Sqr (AO) - Sqr (R)) + sqrtl (Sqr (BO) - Sqr (R)) + R *
Phi;
} else L = AB;
printf ("%.2Lf\n", L);
return 0;
}
Re: I wrote a program, but I got WA. Maybe there are some problems with presision.
> > > Could anybody tell me the trick?
> >
> > writeln (answer:10:2)
>
> I know that. But there are some other problems...
> Here's my code:
There should be a bit more if's.