Number of Triangles Containing The Point (0,0)

前端 未结 1 616
无人及你
无人及你 2021-01-14 04:39

First off, credits to Topcoder, as this problem was used in one of their SRMs (but they have no editorial for it..)

In this problem, I am given n points (where n is

相关标签:
1条回答
  • 2021-01-14 05:27

    Let there be a triangle with 3 points p1=(x_1,y_1),p2=(x_2,y_2) and p3=(x_3,y_3). Let p1,p2,p3 be the position vectors.If origin lies within, then cross product of any one position vector with other two will be different in sign ( one negative , one positive ). But if origin lies outside then there will be one point which has negative cross product with both the other points. So for each point i find points whose cross product is less than 0.Now if you select any two of these points and make a triangle along with point i , origin will be outside this triangle.Thats why you subtract from res ( selection of 2 from such points + point i ). This was by far the best solution many implemented as it did not have the problem of precision with double etc. enter image description here

    0 讨论(0)
提交回复
热议问题