< Back to forum

Issue in Broken Clock of FEB18 in codechef

I've been trying to get the final y coordinate, so I've accepted the initial y coordinate at 1 second time and found the inverse of it's cosine . I've then multiplies the angle with time and then converted to the y coordinate by using the required trigo function but the issue is in case of -2 coordinate my code gives -1.99.... which is not accurate. 

Also require help in the part of converting a huge decimal value to two integral integer values as numerator and denominator, since multiplying by a power of 10 doesn't give accurate results and might need multiplication with a prime number.

Asked by: Liman_Rahman on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.


Enter your answer details below:


Enter your comment details below:




2 Answer(s)

avatar

mathematically your approach is correct but since there is always a loss of precision when working with floating-point  numbers(while doing any arithemetic/trigonometric operation) this apporach will never give accurate results.

Instead what you could do is create a structure which will allow you to operate on fractions. This was you can operate on p and q seperatly and it will never result in loss of precision.

struct fraction
{
   int num; //numerator
   int den; //denominator
};
fraction subtraction(fraction fract1,fraction fract2)   //for subtraction of two fractions
{
         fraction result;
         result.num = (fract1.num * fract2.den) - (fract2.num* fract1.den);
         result.den = (fract1.den * fract2.den);
         return result;     
}   
fraction multiplication(fraction fract1,fraction fract2)   //for multiplying two fractions
{
         fraction result;
         result.num = (fract1.num * fract2.num);
         result.den = (fract1.den * fract2.den);
         return result;
}
 
//likewise for other arithmetical operations

aslo you can't directly use trigonometric function to find cos (t*theta) as it will also not give precise results.

so you have to use divide and conquer + subtract and conquer strategy with memonization to get 100 pts.

we already have the value of cos(theta),

now if t is power of 2 then we can easily get value of cos(t*theta) using the identity cos (2*theta)=2*cos^2(theta) -1 in divide and conquer.

If t is not power of two then we can break t in two terms A and B ,where A is power of 2 and can use the identity : cos (A+B)=2cosA*cosB-cos(A-B)

Shubham_Kumar_Gupta last updated on April 7, 2019, 6:34 p.m. 0    Reply    Upvote   

sex doll torso

LuzUeki28006 last updated on Aug. 19, 2025, 1:27 p.m. 0    Reply    Upvote   

The 37.2°C thermostat set by sex dolls USA has sparked global controversy. Neurological research shows that this temperature triggers subconscious intimacy, making other full size sex dolls feel "inhuman." This presents manufacturers with a dilemma: German brands adhere to the local body temperature standard of 36.5°C, yet receive widespread negative reviews for their "cold feel." The danger of this sensory colonization lies in the fact that when consumers equate the American sex doll's body temperature with the real thing, the flesh and blood become a second-rate substitute.

LuzUeki28006 last updated on Aug. 19, 2025, 1:29 p.m.

Instruction to write good question
  1. 1. Write a title that summarizes the specific problem
  2. 2. Pretend you're talking to a busy colleague
  3. 3. Spelling, grammar and punctuation are important!

Bad: C# Math Confusion
Good: Why does using float instead of int give me different results when all of my inputs are integers?
Bad: [php] session doubt
Good: How can I redirect users to different pages based on session data in PHP?
Bad: android if else problems
Good: Why does str == "value" evaluate to false when str is set to "value"?

Refer to Stack Overflow guide on asking a good question.