LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 02-18-2004, 03:27 PM   #1
devit
Member
 
Registered: Jan 2004
Distribution: Slackware 9.1
Posts: 82

Rep: Reputation: 15
tricky problem


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)?

Thanks!
 
Old 02-18-2004, 06:39 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,524

Rep: Reputation: 93
Homework from school/university?
 
Old 02-18-2004, 07:37 PM   #3
jtshaw
Moderator
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 63
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
 
Old 02-18-2004, 09:21 PM   #4
Squall
Member
 
Registered: Jan 2004
Location: The land of the free and the home of the brave
Distribution: Slack 10
Posts: 239

Rep: Reputation: 30
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.

Last edited by Squall; 02-18-2004 at 09:22 PM.
 
Old 02-18-2004, 09:30 PM   #5
Squall
Member
 
Registered: Jan 2004
Location: The land of the free and the home of the brave
Distribution: Slack 10
Posts: 239

Rep: Reputation: 30
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.

Thanks for the problem, I was bored.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tricky prism54 pcmcia wlan problem stabu Slackware 10 10-07-2005 04:30 PM
TRTP - Tricky Routing Task Problem tokehs Linux - Networking 7 08-27-2004 06:10 PM
Tricky alsa and kernel 2.6 problem. raid517 Linux - Hardware 1 10-01-2003 03:42 AM
Tricky!!!! isajera General 39 08-25-2002 05:52 PM
tricky pppd problem Phish Linux - Networking 1 10-04-2001 03:58 PM


All times are GMT -5. The time now is 05:37 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration