Ferrarixxx's blog

By Ferrarixxx, history, 4 years ago, In English

Hi Guys,
The above picture shows my approach for this problem https://codeforces.com/contest/1354/problem/C1

Am basically using the interior angle subtended by 3 adjacent vertices and then to find the vertical ( perpendicular ) line's length using tan function
But am getting completely unexpected answer.

// -- MY CODE :


long double n;

cin >> n;

// long double angle = (((180 * (2*n — 2)) / (2*n) ) / 360) * 2 * 3.14

long double angle = ((((n — 1)) / n)) * 3.14;

cout << tan(angle) << endl;


PLEASE GUYS HELP ME FIND MY MISTAKE .
THANKS IN ADVANCE.

  • Vote: I like it
  • +6
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

The angle(theta) is half of the interior angle, divide the theta by two and also take pi upto some more decimals to prevent WAs.
I meant in your code...it should be like this.

long double angle = (n - 1) / (2 * n) * 3.14159265359;
  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I have done it like u said but still getting unexpected ans

    Code Snippet:

    #define pi 3.14159265358979323846;

    long double n;

    cin >> n;

    // long double angle = (((180 * (2*n — 2)) / (2*n)) / 360) * 2 * 3.14;

    long double angle = (((n — 1)) / n) * pi;

    cout << tan(angle) << endl;

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

      You didn't see the change I did? I said to divide the angle(theta) by 2 in your code.
      In your code:

      long double angle = (((n — 1)) / n) * pi;
      

      It should be:

      long double angle = (n - 1) / (2 * n) * pi;
      
  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    For maximum precision you can use:

    long double PI = acos(-1);
    
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Hi Guys,
Thanks for the help , i finally solved it .

Am facing another new Problem in C2 (https://codeforces.com/contest/1354/problem/C2)
(This is the last one i promise)
-

In C2 problem this is my simple approach
and again am not able to identify why am getting unexpected output
(Is my approach incorrect?)

Code Snippet :

long double pi = 3.14159265358979323846;

 long double n;
 cin >> n;

 long double theta = (2 * (pi)  ) / 2 * n;

 // long double ans = sqrt( 1 / (2 * (1 - cos(theta))) );

 long double ans = sqrtf( 1 / (2 * (1 - cos(theta))) );

 cout << setprecision(20) << ans << endl;

Please Help me out.

Thanks In Advance. :)

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I don't think what you're doing is correct.
    I may be wrong. But I did something different.
    I think the ideal arrangement should be like this(my drawing's not too good)
    Whats-App-Image-2020-05-29-at-9-40-01-PM
    Here's my code if you want to refer 80726717