|
|
back to boardCommon BoardPlease, help me!!! I get WA in simple problem 1020. I tried to submit this solve many times. But I always get WA! #include <iostream.h> #include <math.h> struct tPt{double x,y;}p1,p2,fs; int n; double dx,dy,r,l; const double PI=3.141592; int main() { cin>>n>>r>>p1.x>>p1.y; fs=p1; l=2*PI*r; for (int i=1;i<n;i++) { cin>>p2.x>>p2.y; dx=p2.x-p1.x;dy=p2.y-p1.y; l+=sqrt(dx*dx+dy*dy); p1=p2; } if (n>1) { dx=p1.x-fs.x;dy=p1.y-fs.y; l+=sqrt(dx*dx+dy*dy); } cout.precision(2); cout<<l; return 0; } Problem with precision (+) try this: l=3.00000 cout.precision(2); cout<<l; the result is 3 (not 3.00) that after using cout, use printf for output float and double with precision.
|
|
|