简体   繁体   中英

Given N points in a 2D plane, determine if there is a line that divides them into two sets of N / 2 points each + some more rules

Given N points on a 2D plane, determine if there is a line that divides them into two sets of N / 2 points each.

There are two more rules:

  • The sum of the distances of each set of points to this line should be the same.
  • The line can't pass through any of the points.

Extras (not sure if helps): We can assume that N is large (~100k); -2000 <= x[i], y[i] <= 2000

Do you folks have any insights to this problem? I really tried many stuff but I believe that I should use some sort of equality, or prove something like: sum(distancesSet1[i]) = sum(distancesSet2[i]). If you want, I can also post here the stuff that I tried and failed (or I think it failed), but before I'd like to see your suggestions.

Thank you so much!

#Edit: What I need to know for this problem is to exactly say whether it's possible or not given the set of N points.

Update: This was an attempt to answer the initial, more general question of whether it was possible to divide the points or not.

The problem as defined by your constraints is mathematically unsolvable. You can't guarantee that the sums of the distances will be equal for both sets.

All you need as proof is a counterexample:

S = [[-1000,0], [0,0], [1,0], [2,0]]

There is only one possible combination to separate the pairs:

S1 = [[-1000,0], [0,0]] 
S2 = [[1,0], [2,0]]

All points are on a line L1 . Given your bullet #2 we can conclude that any line L2 that separate those points will form an angle t wrt L1 . The sum of the distances are then:

sum1 = a*sin(t)   ::   1000 < a < 1002  
sum2 = b*sin(t)   ::      1 < b < 3

   t != 0
sum1 > sum2

QED

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM