I'm the first one, who stuck on this test, my program written in Kotlin (probably, same rules applies to Java). I don't understand, what is "maximum precision"? Should I use double, float or maybe bigdecimal? My program calculates side lengths, area of the triangle (via sides), angles (via sides and acos), and result point C_2. Any help is really welcome! import kotlin.math.* class Point(val x: Int, val y: Int) { constructor(raw: String) : this(raw.split(' ')[0].toInt(), raw.split(' ')[1].toInt()) override fun toString(): String = "$x $y" } class Vector(p1: Point, p2: Point) { private val x = p1.x - p2.x private val y = p1.y - p2.y fun length(): Double = sqrt((x*x + y*y).toDouble()) } fun angle(v1: Vector, v2: Vector, v3: Vector): Double = acos( (v1.length().pow(2) + v2.length().pow(2) - v3.length().pow(2)) / (2 * v1.length() * v2.length()) ) fun triangleSquare(v1: Vector, v2: Vector, v3: Vector): Double { val halvedSideSum = (v1.length() + v2.length() + v3.length()) / 2.0 return sqrt( halvedSideSum * (halvedSideSum - v1.length()) * (halvedSideSum - v2.length()) * (halvedSideSum - v3.length()) ) } fun Double.fuzzyEquals(other: Double): Boolean = (abs(this - other) < 1e-10) fun Double.fuzzyEqualsLow(other: Double): Boolean = (abs(this - other) < 1e-4) fun main() { // input val pointA = Point(readln()) val pointB = Point(readln()) val pointC = Point(readln()) // solution val fixedPointA = Point(0, 0) val fixedPointB = Point(pointB.x - pointA.x, pointB.y - pointA.y) val fixedPointC = Point(pointC.x - pointA.x, pointC.y - pointA.y) val sideAB = Vector(fixedPointA, fixedPointB) val sideBC = Vector(fixedPointB, fixedPointC) val sideAC = Vector(fixedPointA, fixedPointC) val angleBAC = angle(sideAB, sideAC, sideBC) val angleACB = angle(sideAC, sideBC, sideAB) val angleCBA = angle(sideBC, sideAB, sideAC) // find h val h = 2.0 / sideAC.length() * triangleSquare(sideAB, sideBC, sideAC) // tan ACB = h / x val x = h / tan(angleACB) val subtractVectorLength = 2.0 * x val ratio = (sideAC.length() - subtractVectorLength) / sideAC.length() if (ratio <= 0.0 || ratio.fuzzyEquals(0.0) || ratio.fuzzyEqualsLow(1.0)) println("YES") else { println("NO") println(fixedPointA) println(fixedPointB) println( "%.20f".format(fixedPointC.x * ratio) + " ${"%.20f".format(fixedPointC.y * ratio)}") } } Edited by author 22.07.2024 22:53 Pay attention, that points given in order A, B, C. That means that angle of your triangle must equal to angle BAC Edited by author 21.02.2022 17:07 I have got WA at 26 several times. Is there something should i pay attention to ? Thank you. I had WA 26 when I used "cout << x...", but I've replaced it with "cout << setprecision(15) << x..." and it works. Edited by author 15.09.2009 23:17 if you check angle=pi/2, don't use scalar product. and setprecision(10) I keep getting wrong answer at the 2 example. Isn't it from the examples provided? If so, why for 0 0 4 3 6 0 the solution NO 0 0 5 0 1.6 1.2 is not correct? A1B1 is equal to A2B2, B1C1 is equal to B2C2, C1A1 is different from C2A2, the cosine is the same, therefore the angle is the same. For wa#3: 4 0 0 3 0 0 YES For wa#4 0 0 5 0 6 5 YES For wa#5 0 0 4 0 2 3 The possible answer is: NO 0.00000000000000000000 0.00000000000000000000 4.00000000000000000000 0.00000000000000000000 0.46153846153846145000 0.69230769230769285000 But i still have have wa#31. I think, I have problem with precision. Can anyone tell me how to avoid this problem? UPD: Finaly AC. I think, it realy was a problem with precision, but I am not sure. Edited by author 27.07.2011 22:20 Edited by author 27.07.2011 23:58 Yes, problem in precision. EPS = 1e-10 AC EPS = 1e-11 WA#36 Look, using the theorem we could build a triangle with such vertexes: NO -1.0000000000 4.0000000000 0.0000000000 0.0000000000 -0.8780487805 3.9024390244 (img: http://ge.tt/9klV3HC/v/0 ) Could you help me. Why the answer in first test is YES. why not -2 0 -1 4 4 0 Sorry. I have found my mistake. Please tell me why it can't be. I have the same answer on this test 0 0 0 1000 1 0 YES 0 0 1 1000 1 0 YES 0 0 1 1000 2 0 YES Real thanks, Sergey. I had WA3. When I test my program with your tests, I get wrong answer on the second test. My mistake was in comparing the angle ACB with 90 degrees. There was (in C++): if (angle==pi/2.0)... but the right text would be: if (fabs(angle-pi/2.0)<=1e-11)... When I fixed the problem I got AC. Never forget to use EPS when compare real numbers. Without it, result of the work of your program is almost unpredictable 0 0 0 1000 1 0 YES 0 0 1 1000 1 0 YES 0 0 1 1000 2 0 YES 0<=|x|,|y|<=100 But tests are useful :) Edited by author 18.05.2009 12:28If 1000 insted of 100 prevents your program from passing the tests, then your program is really horrible =) P.S. I've written 1000 instead of 100 as a very corner cases specially to test possible error instability. Попытался разобраться как строить треугольник A2B2C2 и случайно додумался вот до такого "доказательства" теоремы Бориса: 0. Дано: A1B1 = A2B2, B1C1 = B2C2, ∠ B1A1C1 = ∠ B2A2C2. 1. По теореме синусов из перечисленного в п. 0 находим, что sin(∠ B2С2A2) = (A2B2 * sin(∠ B2A2C2)) / B2C2 и sin(∠ B1С1A1) = (A1B1 * sin(∠ B1A1C1)) / B1C1. Значит угол ∠ B2С2A2 = ∠ B1С1A1. 2. Соответственно, оставшийся угол A1B1C1 = A2B2C2 (следствие из суммы углов в треугольнике). 3. Теорема доказана! Если найдете ошибку в доказательстве - значит решите задачу ;) Wrong is decision in punct 1. I don't pusblish it, because it will be serious prompting. i mean if: AB<=BC or <ACB=90' or <BAC>90' then YES miss something? if <BAC>90' then AB<=BC is always true Edited by author 22.04.2009 19:34 Edited by author 22.04.2009 19:34 (AB<=BC) || (BCA==90) || (BAC>=90) verify in int and if No 1001 ways for approximating calculations after PS: It is possible to make mistake about ==90 ABC==90 - May be! and it is test 26 Some time I was under influence of the fact that in 90-triangles for equality is enought 2 elements. Also it is interesting that special cases should verified under integer considerations all times because numeric methods are bad near this cases due big error multiplicators. Edited by author 31.05.2009 09:41 What is this test? I don't know what is this test's but I use some things: 1.Coordinate's shift to (0,0) 2.Checking: Angle(a,c,b)==90 Angle(a,b,c)>=90 Pay Attention to: VectorProduct(ac1,ac)>0, where c - is old C, c1 - new position of C Good Luck. |
|