Problem 165
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.
This forum is NOT meant to discuss solution methods for a problem.
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.
This forum is NOT meant to discuss solution methods for a problem.
In particular don't post any code fragments or results.
Don't start begging others to give partial answers to problems
Don't ask for hints how to solve a problem
Don't start a new topic for a problem if there already exists one
Don't start begging others to give partial answers to problems
Don't ask for hints how to solve a problem
Don't start a new topic for a problem if there already exists one
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
-
quilan
- Posts: 182
- Joined: Fri Aug 03, 2007 11:08 pm
Problem 165
If an endpoint lies on an intersection of two other lines, does that mean that the intersection is invalid?
Example w/ three lines:
(-1,0)-(1,0)
(0,-1)-(0,1)
(0,0)-(1,1)
Would (0,0) not count as a distinct intersection point?
Example w/ three lines:
(-1,0)-(1,0)
(0,-1)-(0,1)
(0,0)-(1,1)
Would (0,0) not count as a distinct intersection point?
ex ~100%'er... until the gf came along.


- daniel.is.fischer
- Posts: 2400
- Joined: Sun Sep 02, 2007 11:15 pm
- Location: Bremen, Germany
Re: Clarification on 165
The first two lines properly intersect at (0,0), so it counts. If the first segment wasn't there, (0,0) would not count (unless other segments would properly intersect there).
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
-
viv_ban
- Posts: 23
- Joined: Mon May 26, 2008 3:09 pm
clarification on problem 165
In problem 165 it has been asked "to identify distinct true intersection points". Does that mean concurrency of lines has to be taken into consideration (if any)?
- jaap
- Posts: 588
- Joined: Tue Mar 25, 2008 3:57 pm
- Contact:
Re: clarification on problem 165
Yes, if there are three or more lines that intersect in a single point, that intersection point should still be counted only once.
- DNS
- Posts: 30
- Joined: Thu Oct 16, 2008 9:32 am
- Location: Ukraine, Nikolaev
Re: Clarification on 165
Using different precision to check is a point belong to the segment I obtain different results (all are incorrect).
Only == (long double) ...1680
abs(.-.)< 1E-15 ...1560
abs(.-.)< 1E-9 ...1557
abs(.-.)< 5E-9 ...1544
abs(.-.)< 1E-8 ...1518
abs(.-.)< 5E-8 ...1398
What precision should I use? Or my way is wrong?
Only == (long double) ...1680
abs(.-.)< 1E-15 ...1560
abs(.-.)< 1E-9 ...1557
abs(.-.)< 5E-9 ...1544
abs(.-.)< 1E-8 ...1518
abs(.-.)< 5E-8 ...1398
What precision should I use? Or my way is wrong?
2 x 2 = 4 = true
-
quilan
- Posts: 182
- Joined: Fri Aug 03, 2007 11:08 pm
Re: Clarification on 165
Try it with arbitrary precision and see what your results are.
ex ~100%'er... until the gf came along.


- DNS
- Posts: 30
- Joined: Thu Oct 16, 2008 9:32 am
- Location: Ukraine, Nikolaev
Re: Clarification on 165
It seems funny, but in the example (3 segment) "not-true" intersection point (22,40) after my brute-force calculation (line-line intersection) deflects from (22,40) by ~1E-15. When I use (x_calc < x_seg) condition, it passed, but really should be x_calc==s_seg. So, I confused.
2 x 2 = 4 = true
- hk
- Administrator
- Posts: 12831
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Clarification on 165
Or better still, try to do all in integers, using fractions.quilan wrote:Try it with arbitrary precision and see what your results are.

War ruins the life and health of untold numbers of innocent children.
-
DaveNo1
- Posts: 10
- Joined: Sat Oct 25, 2008 4:36 am
Re: Clarification on 165
I used fractions, and every manual check says that it produces valid results, but something still appears to be wrong.hk wrote:Or better still, try to do all in integers, using fractions.
With only 100 line Segments I get 1112 Intersections. Is that a correct value?
- stijn263
- Posts: 1505
- Joined: Sat Sep 15, 2007 11:57 pm
- Location: Netherlands
Re: Clarification on 165
stijn263 wrote:Problem 165 can go wrong on many points. Just to name a few:
-> Are you checking wether more than 2 lines intersect at a point ?
-> What about linesegments that are exactly the same (perhaps partly)?
-> Do you store intersection points using floats or integer fractions?
-
karlo
- Posts: 107
- Joined: Tue Dec 02, 2008 5:32 pm
- Location: Cambridge, MA
- Contact:
Re: Clarification on 165
Because it's very easy to do a mistake while counting those distinct intersection points, I do believe that an intermediate result (the first 100 segments for example) would be very useful.
EDIT:
@DaveNo1: I get 1112 for 100 segments too, but I didn't solve the problem, so my result may be wrong:( Anyway I see now that hk is right: the answer for 100 wouldn't help too much.
EDIT:
@DaveNo1: I get 1112 for 100 segments too, but I didn't solve the problem, so my result may be wrong:( Anyway I see now that hk is right: the answer for 100 wouldn't help too much.
Last edited by karlo on Thu Dec 11, 2008 1:17 pm, edited 1 time in total.
- stijn263
- Posts: 1505
- Joined: Sat Sep 15, 2007 11:57 pm
- Location: Netherlands
Re: Clarification on 165
Yup, that's why it's a difficult problemkarlo wrote:Because it's very easy to do a mistake while counting those distinct intersection points, (..)
- hk
- Administrator
- Posts: 12831
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Clarification on 165
That would not guarantee that some possible issues would have been covered and in that sense is useless.karlo wrote:Because it's very easy to do a mistake while counting those distinct intersection points, I do believe that an intermediate result (the first 100 segments for example) would be very useful.

War ruins the life and health of untold numbers of innocent children.
-
karlo
- Posts: 107
- Joined: Tue Dec 02, 2008 5:32 pm
- Location: Cambridge, MA
- Contact:
Re: Clarification on 165
Can't see why this makes a difference. Maybe I don't understand what you mean exactly. Even if two segments are the same, that doesn't affect the number of distinct points. Still getting a wrong answerstijn263 wrote:Problem 165 can go wrong on many points. Just to name a few:
-> What about linesegments that are exactly the same (perhaps partly)?
- DNS
- Posts: 30
- Joined: Thu Oct 16, 2008 9:32 am
- Location: Ukraine, Nikolaev
Re: Clarification on 165
If we change the last segment onto (-1,-1)-(1,1), such that in (0,0) point intersect 3 segments. How many times should I add the point?quilan wrote:If an endpoint lies on an intersection of two other lines, does that mean that the intersection is invalid?
Example w/ three lines:
(-1,0)-(1,0)
(0,-1)-(0,1)
(0,0)-(1,1)
Would (0,0) not count as a distinct intersection point?
I see no confirmation for 1112 points for 100 seg-s. I found 1119 points of true itersection and noone of non-true. Am I wrong?
2 x 2 = 4 = true
- jaap
- Posts: 588
- Joined: Tue Mar 25, 2008 3:57 pm
- Contact:
Re: Clarification on 165
Once:DNS wrote:If we change the last segment onto (-1,-1)-(1,1), such that in (0,0) point intersect 3 segments. How many times should I add the point?
Problem 165 wrote:How many distinct true intersection points are found among the 5000 line segments?
-
Smaug
- Posts: 15
- Joined: Thu Aug 06, 2009 5:08 pm
Re: Problem 165
I get 1130, consistently, whether I use extended precision or fractions represented as numerator/denominator throughout. I don't even do any division on the fractions!
- rayfil
- Administrator
- Posts: 1412
- Joined: Sun Mar 26, 2006 5:30 am
- Location: Quebec, Canada
- Contact:
Re: Problem 165
There must be something VERY wrong with your algo.Smaug wrote:I get 1130, consistently, whether I use ...!
When you assume something, you risk being wrong half the time.
- Lord_Farin
- Posts: 239
- Joined: Wed Jul 01, 2009 10:43 am
- Location: Netherlands
Re: Problem 165
Is there anyone willing to take a look at my code, since I have reworked the algorithm today, improving my Fraction class where necessary, but without obtaining the green check. Quite simply, I'm stuck. Thanks in advance

-
sivakd
- Posts: 217
- Joined: Fri Jul 17, 2009 9:37 am
- Location: California, USA
- Contact:
Re: Problem 165
Does your fraction class represent the value in float or use integers for n and d (n/d)? For me the later form worked. This is one of those problems where I just scrapped the whole program and started fresh to avoid so many bugs.

puzzle is a euphemism for lack of clarity
