ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1075. Thread in a Space

If you have trouble on test#8 or #48
Posted by Rotter Tarmination 27 Nov 2025 21:55
All the trouble are caused by precision.

The first submittion includes the code:
angle_ACB = math.acos((x1*x2+y1*y2+z1*z2) / (len_CA*len_CB))
Then I got RE#8 in python, WA#8 in C++.

Next I change the code to:
angle_ACB = math.acos(0.5*(CA_sqr + CB_sqr - len_AB**2) / (len_CA*len_CB)) in python
angle_ACB = acos(0.5* (CA_sqr + CB_sqr - sqr(len_AB))/(len_CA*len_CB)) in C++
Then I got RE#48 in python, WA#48 in C++.

So I am sure the trouble is caused by the precision because of the function sqrt()!
Sometimes, the cos(angle_ACB) is smaller than -1.
Then the problem occurred by using acos(x) if x<-1.
You need to handle this situation.