Try this test: -10 -1 1 -1 8 1 -7 2 1 3 Answer: 14.38 I know that the task was rejudged. I added the condition for new test, where A, B and C collinear: cos(ACB) - 1.0 < eps, where eps = 1e-8, then answer = AB, but I've still get WA 48. Give me a hint, please. Thanks in advance. Now already accepted, I have found stupid bug in my code. Ignore first message. And what bug did you found? Just like you I've added a condition for test: 2 4 0 3 6 0 0 0 0 3 The answer is not NaN now, but I still have WA48. Try cases when all points belongs to one axis only: Case 1: 6 0 0 2 0 0 4 0 0 1 Case 2: 0 6 0 0 2 0 0 4 0 1 Case 3: 0 0 6 0 0 2 0 0 4 1 For all cases correct answer will be 4.51 Good luck! You should add some test. So my AC programm give wrong answer on this test 20 0 0 -20 0 0 0 0 0 10 --- Write answer is 51.42; and my answer is 45.11 Please do something!!! Sorry! I understood my mistake. 45.11 is the correct answer this may be true: 1.000 > 1. so add this func: double acos1(double x) { if(x > 1) x = 1; if(x < -1) x = -1; return acos(x); } Big thanks, god, without that, my program was stopped at test 8. It's actually 1.00000000000000001, not 1.000 BTW, same stuff should be applied to 'sqrt'. if(v<0 && v>-eps) v = 0; sqrt(v); Thank you very much! I had WA 24, "safe" acos didn't help, but "safe" sqrt did, I got AC. I used it so: double sqrt1(double a) { if (a<0) return 0; return sqrt(a); } Edited by author 31.07.2015 13:17 thanks a lot, never would have figured out :) THANKS!!!!!!!!!! It really helped me! After small fix - AC :) thanks so much, i got ac with your func... New tests have been added to the problem which exploit a common mistake when using acos function. Hint: try to calculate acos(sqrt(3.0) * sqrt(3.0) - 4.0) in your programming language. 649 authors (60%) with accepted solutions have been challenged. Why point out the weak place!? I've found mistake without this hint, it wasnt that hard. Submission ID 7846927 (not my source, found online) gets Accepted but on this test it prints nan: 2 4 0 3 6 0 0 0 0 3 I'm pretty sure the test is correct (I plotted it). It's a sphere with center in origin and two points co-linear with the center which lie outside the sphere. Submission ID 7846930 (also found online) also gets Accepted despite printing nan on the test above. Edited by author 12.04.2018 03:03 Edited by author 12.04.2018 03:08 Thanks! The bunch of tests of similar pattern has been added. If you already have solved (simpler!) "1285. Thread in a Hyperspace", just replace N=8 with N=3. That's how I get AC after so much time. Edited by author 06.09.2013 22:11 #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. First, Anatoly's tip helped me (see "WA#4 - I don't know why" thread). Another one tip for those receiving WA with "swear correct algo": I've multiplyed whole input data to some koef (tried 500, 800) and divided result by this koef before printing — got AC while without it got WA on 8-th test. It's all about error of calculations. And, of course, I've used double, not float. AB, AC, BC - Vectors. r - Radius. Arctangent(y, x) - Coprocessor function FPATAN, calculates an angle between vectors A(x, y) and X(1, 0)(using y and x coordinates of the A point). My algorithm: d = Abs(VectorMultiply(AC, BC)) / AB if (d >= r) then Write(Length(AB)) else begin s1 = Sqrt(Length(AC) * Length(AC) - r * r) angle1 = Arctangent(Sqrt(Length(AC) * Length(AC) - d * d), d) - Arctangent(s1, r); s2 = Sqrt(Length(BC) * Length(BC) - r * r) angle2 = Arctangent(Sqrt(Length(BC) * Length(BC) - d * d), d) - Arctangent(s2, r); s = r * (angle1 + angle2) Write(s1 + s + s2) end ----- Am I wrong? I think if you'll get following test, then you'll get 4th. 1 2 0 3 3 0 0 0 0 2 The answer is 2.24 (not 2.30) Thank's Anatoly, that helped me. Don't know, how I've missed this :) I got AC as I changed all ints to longs. I thought ints would be sufficient to do the sum. Still can't figure out why longs are needed. What is wrong with my code? I can't figure out by myself:( Some people talking about some tricky case. What is it? Check your code for the extreme cases. -1000 -1000 -1000 1000 1000 1000 0 0 0 0 I've found that sqrt returns NaN for values below 1e-8 (approximately). Your test is incorrect, because R must be a positive integer. > I've found that sqrt returns NaN for values below 1e-8 (approximately). I cannot know what compiler you use, but in my GCC (and judge's MSVC) there is several functions for finding a square root: ___ float sqrtf(float); ___ double sqrt(double); ___ long double sqrtl(long double); and the last two compute a proper value for 1e-8. Edited by author 28.07.2011 02:49 Well, I solved a mysterious case of WA #8. :-) Just checked every double variable whether it is NaN. I had a working program, but get WA only because of acos function. When I had started to use something like this instead of acos: > double arccos(double x) { > x = min(1.0d, max(-1.0d, x)); > return acos(x); > } I got AC. Hi. Can you explain me, why this function of arccos is working correctly?) Because our program does not accepted without it. Try to increase your EPS, I got AC with EPS = 1e-7 Somehow I managed to get AC without EPS. That's pretty weird since I was using acos. %) I had WA10. When I had used the following simple test, I have found mistake and got AC: -10 10 0 10 10 0 0 0 0 8 Right answer is 20.00 I had WA10 too, but my programm write rigth answer for this test. Help me with this. 1 1 1 1 1 1 0 0 0 0 ans=0 > A radius of the ball is R, a ___positive___ integer number. I had WA28. After two hints I get AC. 1) check if A=B 2) check if sphere has intersections with segment using long long integers, not doubles Edited by author 06.02.2011 08:52 Edited by author 24.04.2012 15:50 oh my bad... never mind! i just got that i need to search for tangent planes, so it gives the shortest distance... Say me please how you are checking intersection with first article. I can't understand formulas. I had WA 11 and this test helped me: 0 0 0 0 0 10 0 1 168 7 Correct answer is 10.00. In short the problem is that the distance between C and the line between A and B is less then R but still the thread doesn't pass through the ball. |
|