|
|
here's my code. I've tried many testes but i've passed them\ #include <iostream> #include <iomanip> #include <cmath> using namespace std;
double f(double r, double a) { double rad=(a*4*atan((double)1))/180; double da=sqrt( 2*r*r-2*r*r*cos(rad) ); return da; }
int main() { double r,a,re,da,nr,rad; cin>>r>>a; re=r; nr=floor((double)180/a); da=f(r,2*a); re+=((nr-1)*da); double mod=360-floor(360/(2*a))*(2*a); //cout<<mod<<'\n'; if(mod) re+=f(r,mod); cout<<fixed<<setprecision(6)<<re; return 0; } Algorithm right, but what in 8 test? Please, give me test; Many times my code was reviewed and rewatched, but still WA7. Could anybody help? What wrong with code? May be this algorithm gives not the optimal path? int main() { double r, a; std::cin >> r >> a; // first, walk to the edge of the island double s = r; // total angle of undiscovered edge const double a_left = 360.0 - 2.0*a; // hops count on 2*a "arc" line const int full_hops = (int)(a_left / (2.0*a)); s += range(r, to_rad(2.0*a)) * full_hops; // remaining angle to hop double a_rem = a_left - full_hops * (2.0 * a); s += range(r, to_rad(a_rem)); std::cout << std::fixed << std::setprecision(12) << s << std::endl; } Your algorithm allows me to AC. Maybe problem in calculations, in "to_rad" or "range"... I wrote to_rad and range to compile your code, and compared my code with yours: all output is identical. So, maybe you've mistook in one of these functions. Edited by author 18.10.2009 00:00 Thank you a lot for a great advice! Problem was eliminated after rewriting range() function: Old: used cosinus theorem New: using sinus to radius multiplication AC! Dmitriy S. Hodyrev! You solved 1726. If you read this, help me, please. My e-mail in my profile. Moders, sorry for the message concerning not this problem. But did you think about a functionality of allowing users to send private messages to the other users' e-mails through a web-form? I had the same problem: Since the cosine can be quite close to zero its square root is not calculated properly. So I also didn't use cosine theorem but calculated the length of the chords with simpler geometry: long double x = radius * cos(angle); long double y = radius * sin(angle); long double ans = sqrt((x - radius) * (x - radius) + y * y); Here the square root is done over the distance, not over the cosine, which, as it seems, solved the problem. Use the law of sines instead of cosines. Test is 10.000 29.999 Correst answer is 60.000583 What is wrong? My answer is: ans=((int)(360/(2*a)-1))*2*r*sin((a*pi)/180)+r I HAVE THE SAME PROBLEM PLEASE HELP US.... My program is : #include<iostream> #include<cmath> #define PI 3.14159265358979323846264338327950288 using namespace std; double r,a,whole,reminder,side,leftSide; int main() { cin>>r>>a; whole=180/a; reminder=360-whole*(2.0*a); side=2*r*sin(a*PI/180); leftSide=2*r*sin(reminder*PI/360.0); printf("%.12lf",r+(whole-1)*side+leftSide); system("pause"); return 0; } you forget about last part for ex input 1 40 you have 3 part with arch = 80 degrees and last 40 degrees (not 80) SOrry for my english I hope that you understand Test 5: Input 10.000 30.001 Output 59.999698 For accuracy of calculations use power-reduction formulas /* 2 * sin ^ 2 (a) = 1 - cos(2a) */ in the formula that calculates chords long. 2 * R * sin( a / 2 ) = sqrt ( 2 R R 2 sin^2 ( a / 2 ) ) = sqrt ( 2 R R ( 1 - cos ( a ) ) = sqrt ( 2 R R - 2 R R cos ( a ) ) = sqrt ( R^2 + R^2 + 2 * R * R * cos ( a ) ) path consist of 6 steps: 1) one step: from center to edge (1 meter) 2) five steps: counterclockwise along 60 degree arc (1 meter each) total 6 meters |
|
|