Where am I going wrong? HELP OBTTRNGL

https://www.codechef.com/viewsolution/15054629

This is the link to my solution. Please tell me why am I getting wrong answer.

Same for me:???
https://www.codechef.com/viewsolution/15055459

Your code is giving wrong output 38 for this test case…

1

78 7 46

but output should be 0 because of half circle. And while you are calculating ang… Because of precisions ang is coming 179.99999999999997 and not 180… so giving wrong answer.

Hope this will help… :slight_smile:

As @kauts_kanu has rightly said, your variable ang is of double type. However, you are trying to compare it with an int. This scenario is never recommended as its behavior is undefined due to precision issues. Because then it depends on the architecture how it decides to truncate or extend extra bytes for comparison. In fact, it is not only with integer types, you should never try to check “equality” with double or floats (not even between double and double). Although, you could use other comparison ops like < or >. If you really want to check equality of doubles, then do it with delta’s like:

double x = 5.0
double y = 5.0
double delta = 0.000000000000001
if(abs(x-y)< delta) print "they are equal"
else print "not equal"

Instead of trying to calculate the angles, you can just count how many candles lie between the lit ones on either side. Whichever is lesser, print that, and if it’s equal, print zero.
So, if out of 6 candles, 1 and 3 are lit, there is candle 2 in between them on one side and 4, 5, 6 on the other side. Here the answer will be 1.

1 Like

Well the solution to this question needs to have the following considerations:
1. If AB forms the diameter, whichever point you pick between A and B, the angle ACB will be 90.Hence in this case there will be 0 obtuse angled triangle.
2. Of the circle , pick the point lying between the shorter segment of the circle.
Example :k=11, A=1,B=7. In this case we get the shorter segment with numbers (7,8,9,10,11,1). So the points lying between 7 and 1 in this segment will be your answer,i.e. 8,9,10,11. So the output will be 4.
3. And also observe that in this questions that A is not always greater than B. It is only mentioned that a=A is not equal to B.
Apply these concepts on your code. You will get the Correct Answer. Don’t miss out on any of these.
Good Luck!!

My solution with explanation…

import java.util.*;

class Main
{

public static void main(String[] args){
    Scanner in = new Scanner(System.in);
    int T = in.nextInt();
    while(T-->0){
        int k = in.nextInt(), A = in.nextInt(), B = in.nextInt();
int min = Math.min(A,B), max = Math.max(A,B);
// using min and max
// to avoid complication of cases where A>B
// case where AB is diameter of circle
        if(k%2==0 && max-min == k/2)System.out.println(0);
        else{
//all the points of the segment having less number of points will make obtuse angle with A and B
// Number of points in:
// Segment 1 = max- min-1
// Segment 2 = min + k -max - 1
// minimum of above two is our answer
System.out.println(Math.min(max-min-1, min+k-max-1));
        }
    }
}

}

A link to my actual code.
https://www.codechef.com/viewsolution/15040270

Please upvote this if u find this helpful… :slight_smile: