Sign in to follow this  
afroboy

Help with Contest problem

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 this post


Link to post
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[i] 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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this