karthiflash Posted June 22, 2008 Posted June 22, 2008 I am not clear what result do u actually expect here>
Diggsey Posted July 25, 2008 Posted July 25, 2008 Add up all the values in the cost array, except the last one, and subtract it from the total cost. Divide what's left by the last value in the array, and round it down to the nearest whole number. Do the same thing for the times array. When you have the two results, find the smaller one, and if it's less than 0, make it zero and return it from the function You're 3rd example seems to be wrong, but the others are all right...
Frankie Posted July 26, 2008 Author Posted July 26, 2008 The examples are part of the problem statement and all of them are right. You method doesn't work, take #3 for example: {1, 1} {3, 12} 100 27 Returns: 6 Lets say the cost is in $... each unit costs $1, the first takes 3 sec and the second takes 12 sec. You have a total of $100 to spend and 27 secs. Using you method, you'll make 1 of the first unit, spending $1 and 3 seconds leaving you with $99 and 24 seconds. If you just keep making the 2nd unit from this, you'll only end up with 2 of them. If you make more of the first unit, then they can each simultaneously create the second type of units allowing more to be built in the allotted time.
Diggsey Posted July 27, 2008 Posted July 27, 2008 Ah, I didn't realise that more than one could be being built at the same time. It sounds like you could use a recursive function. All you have to do is call the function for every possible combination of units that can be built. Once that function has built those, it then calls itself for every new combination, and so on until all the combinations are exhausted. Then, find the one that created the most of the highest level unit. Only count a combination if you have enough time and money for it.
Frankie Posted July 27, 2008 Author Posted July 27, 2008 I probably should have mentionned this before, I already know that's how it should be solved, I just don't know how to create one that can solve any one of those problems in less than 2 seconds.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now