Home > Back-end >  In asking who teach!!!!!! It's really difficult to c...
In asking who teach!!!!!! It's really difficult to c...

Time:06-09

Bamboo is the most like to eat bananas,
Now there are three has a number of banana trees, the first tree on a banana, a second banana tree is b, the third c banana tree,
Each time he can do one of two kinds of operations:
1. Take a banana from the first tree, two bananas from the second tree (only when the first tree at least a banana, the second tree at least two bananas, to carry out the operation).
2. From the second tree a banana, two bananas from the third tree (only when the second tree at least a banana, the third tree at least two bananas, to carry out this operation),
He want to get the largest number of bananas, but he doesn't know what to do, for a start, he have no bananas, can you help him?

CodePudding user response:

A greedy algorithm,
We take the first tree take 1 banana, we may also obtain the second tree 2 bananas, but we would lose the third tree four bananas, because without the second tree 2 banana; Price=1 + 2-4-1
We take 1 banana from the second tree, we could also take 2 banana tree from the third tree, at the same time, we will be on the first tree for less 1/2 banana tree; Price, 1 + 2-0.5=2.5

So, greedy and intelligent man should take the banana tree, tree and 3 2 to take the first tree and the second tree a banana,

Or, can think so, anyway, we will be from the second tree take bananas, assuming that take unit 1,
If choose the first scheme, can again take 0.5 bananas from the first tree,
But if the option 2, can again take 2 bananas from the third tree,

CodePudding user response:

It is difficult to C language? What language do you feel easier?

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related