Help with Contest problem

This topic is 4137 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Heres the problem Calculate the number of table arrangement so that any two cows sitting next to each other dont differ in height by no more than K inches. so for: 4 10 2 16 6 10 There are 4 cows, with heights 2, 16, 6, and 10. Two cows whose heights differ by more than 10 do not want to sit next to each other. Can anyone just give me some hints, i am completely stuck

Share on other sites
What are you after, code or just some help on abstracting and solving the problem?

I'd say some kind of comparison needs to be made - if you've got an array of cows within your program, element and element[i+1] cannot differ by >10.

Consequently, if difference between Cow A and Cow B <=10, they can sit in adjacent array indices. However, if you're trying to sort it into order i.e. cow with height 1 at position [0], cow with height 4 at [1], cow at height 7 at [2], cow with height 19 not at position [3] because of our difference of 10 rule... then that's another story. That, in my mind, could wind up being quite complicated.

Not sure if I should be helping, actually - is this a contest like you say, or is this homework? We're not supposed to help with homework. I don't know if it's forum policy, but it's frowned upon.

Share on other sites
I would help you in this contest but I already gave the answers to all of the questions to one of your competitors because I want him to win. Sorry.

Share on other sites
if runtime efficiency isn't a problem, build a search tree and search it.

1. 1
Rutin
25
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 9
• 9
• 46
• 41
• 23
• Forum Statistics

• Total Topics
631749
• Total Posts
3002054
×