Блог пользователя Ferrarixxx

Автор Ferrarixxx, история, 6 лет назад, По-английски

Hi Guys,
The above picture shows my approach for this problem https://codeforces.me/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.

  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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;
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

Am facing another new Problem in C2 (https://codeforces.me/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. :)