ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I have found a nice problem but I couldn't give an appropriate answer to it:
I read from a file n straight lines from their equations (Ax+By+C=0 so I read A, B and C). I have to tell how many polygons the lines determine(only the polygons that can't be broken up will be counted).
for example the equations of four straight lines:
x=0
y=0
x+y-1=0
x-y=0
The answer is 2 but how can I get there in less than a second(surely not backtracking)?
Can you solve it mathematically? Once you can do that this problem is very easy. But I suggest you take a few examples, plot them on a piece of paper, and look at the trends.... I remember grading that one as a TA
Location: The land of the free and the home of the brave
Distribution: Slack 10
Posts: 239
Rep:
I'm a little confused, I'm not sure what you are trying to solve for? Are you trying to find the roots of the quadratic? I may be able to find a solution if you tell me what I'm trying to solve.
edit: sorry nevermind, I read the post more thorougly and you did indeed address what you are trying to find.
Location: The land of the free and the home of the brave
Distribution: Slack 10
Posts: 239
Rep:
What I'd do with what you have is simply graph the points. The number of polygons the lines make when they intercept it should be the answer. And no, you probably won't ever be able to get there in a second. Some math problem require a bit more.
Let's see if it works
x=0
y=0
x+y-1=0 (y=-x+1)
y=x
hold on a minute...
Yep, we got ourselves two polygons.
NOTE: I'm only in 10th grade, so don't assume I'm right without asking your professor or someone, that's just how I'd do it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.