Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

### Ferrarixxx's blog

By Ferrarixxx, history, 6 weeks ago, ,

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 .

• +6

 » 6 weeks ago, # | ← 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 weeks ago, # ^ |   0 I have done it like u said but still getting unexpected ansCode 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;
•  » » » 6 weeks ago, # ^ |   +8 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; 
•  » » 6 weeks ago, # ^ |   0 For maximum precision you can use: long double PI = acos(-1); 
•  » » » 6 weeks ago, # ^ |   0 Yeah right!
 » 6 weeks ago, # |   0 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. :)
•  » » 6 weeks ago, # ^ |   0 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) Here's my code if you want to refer 80726717
•  » » 6 weeks ago, # ^ |   0 My above illustrated approach for the problem https://codeforces.com/contest/1354/problem/C2 is correct : 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 = 2 * (long double)sqrtf( 1 / (2 * (1 - (long double)cos(theta))) ); cout << setprecision(20) << ans << endl;This code is working fine but it lacks precision. i.e for this testcase : 3 3 5 199 These are the actual answers : 1.931851653 3.196226611 126.687663595but my code outputs this : 2 3.2360680103302001953 126.68865203857421875IF ANYONE CAN HELP ME HERE THEN PLEASE TYPE A COMMENT
•  » » » 6 weeks ago, # ^ |   0 Can Anyone help me out here to increase precision of my above code ??If its not possible then atleast type a comment 'not possible', then i'll stop asking.
•  » » » » 6 weeks ago, # ^ |   0 Maybe change pi to be = acos(-1);It's just c++, your answer is correct.