bzoj#P1750. [Usaco2005 qua] Apple Catching
[Usaco2005 qua] Apple Catching
题目描述
It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered and ) in his field, each full of apples. Bessie cannot reach the apples when they are on the tree, so she must wait for them to fall.
However, she must catch them in the air since the apples bruise when they hit the ground (and no one wants to eat bruised apples). Bessie is a quick eater, so an apple she does catch is eaten in just a few seconds. Each minute, one of the two apple trees drops an apple. Bessie, having much practice, can catch an apple if she is standing under a tree from which one falls.
While Bessie can walk between the two trees quickly (in much less than a minute), she can stand under only one tree at any time. Moreover, cows do not get a lot of exercise, so she is not willing to walk back and forth between the trees endlessly (and thus misses some apples). Apples fall (one each minute) for minutes. Bessie is willing to walk back and forth at most times.
Given which tree will drop an apple each minute, determine the maximum number of apples which Bessie can catch. Bessie starts at tree .
输入格式
- Line :Two space separated integers: and .
- Lines : or :the tree that will drop an apple each minute.
输出格式
- Line : The maximum number of apples Bessie can catch without walking more than times.
7 2
2
1
1
2
2
1
1
6
样例说明
Seven apples fall - one from tree , then two in a row from tree , then two in a row from tree , then two in a row from tree .
Bessie is willing to walk from one tree to the other twice. Bessie can catch six apples by staying under tree until the first two have dropped, then moving to tree for the next two, then returning back to tree for the final two.
数据规模与约定
对于 的数据:,。
题目来源
Usaco2005 qua