|
|
back to board#include<iostream> #include<stdio.h> #include<math.h> using namespace std; struct point { double x; double y; double z; }; double pi=3.14159265358979323846; int main () { point a,b,c; double tanga,tangb,distac,distbc,ang,arc,r,angpt; cin >> a.x >> a.y >> a.z >> b.x >> b.y >> b.z >> c.x >> c.y >> c.z >> r ; distac=sqrt((a.x-c.x)*(a.x-c.x)+(a.y-c.y)*(a.y-c.y)+(a.z-c.z)*(a.z-c.z)); distbc=sqrt((b.x-c.x)*(b.x-c.x)+(b.y-c.y)*(b.y-c.y)+(b.z-c.z)*(b.z-c.z)); tanga=sqrt(distac*distac-r*r); tangb=sqrt(distbc*distbc-r*r); angpt=acos(((a.x-c.x)*(b.x-c.x)+(a.y-c.y)*(b.y-c.y)+(a.z-c.z)*(b.z-c.z))/ (sqrt((a.x-c.x)*(a.x-c.x)+(a.y-c.y)*(a.y-c.y)+(a.z-c.z)*(a.z-c.z))* sqrt((b.x-c.x)*(b.x-c.x)+(b.y-c.y)*(b.y-c.y)+(b.z-c.z)*(b.z-c.z))))*(180/pi); //angle between the two vectors AC and BC ang=angpt-(((atan2(tanga,distac)+atan2(tangb,distbc))*(180/pi))); ang/=360; arc=ang*2*pi*r; printf("%.2lf",tanga+tangb+arc); cout << endl ; return 0; } I know that I have to check if there could be a straight line but I think that the sample test should be right for my program. My program writes 19.78 not 19.71. Thanks in advance. Should be ang=angpt-(((asin(tanga/distac)+asin(tangb/distbc))*(180/pi))); Also, why don't you get rid of these annoying 180/pi, /=360? Try to calculate in radians. Edited by author 31.07.2013 03:04 Edited by author 31.07.2013 03:07 Help I have WA8. Then I multiplied the whole data with 500 and divide the output with 500 and then I have WA9. Why does printf doesn't work? Edited by author 31.07.2013 21:12 I really have no idea. Again, try to get rid of redundant * and / — they can cause error via rounding (though I don't believe these roundings are so influential). If not, try maybe to play with different ways of calculating some values in triangles (sin or cos or tan). Btw, problem 1042 is much more interesting for me. You solved it, good job. Thanks but you solved this problem so and for you good job. I found out that when you use printf for long long int you should write printf("%ld...); not lld and for double you should write printf("f....); not lf. I'll be glad if this will help someone. |
|
|