8447: Cow Run

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Problem 2: Cow Run [Mark Gordon, 2011] Farmer John and Bessie have devised a new exercise game for the cows. The cows are running on a circular track of length M (2 <= M <= 1,000,000,000) starting from the same position. The game proceeds in N (1 <= N <= 14) rounds using a deck of 8N cards each with a number X_i (0 <= X_i < M) written on it. Each round FJ moves the top 8 cards into a separate pile and selects either the top 4 or bottom 4 cards for Bessie to play with. Bessie then chooses either the top 2 cards or bottom 2 cards of the 4 cards FJ selected. After this FJ calls out the number on the top card, X_top, and the cows run a distance of R * X_top, where R is the total distance the cows have run so far. Bessie then calls out the number on the bottom card, X_bottom, and the cows run a distance of X_bottom. FJ is concerned that after the exercise the cows will be too tired to get back to the beginning of the track if they end up too far away. He believes if the cows end up more than a distance of K (0 <= K <= floor(M/2)) from their starting position they won't be able to get back home. It is guaranteed that if FJ plays correctly, he will always be able to ensure the cows can come home, irrespective of the moves made by Bessie! For each round, your task is to determine which half of the cards FJ should choose such that no matter what Bessie does from that point on, FJ can always get the cows home. Bessie will then make the move provided in the input and you can then continue onto the next round. Note that even though Bessie's moves are provided to you in the input, you are to specify moves for FJ that would have worked no matter what Bessie chooses (so it is effectively as if FJ does not really know what Bessie will do during her moves).


约翰和贝茜为奶牛们设计了一个全新的运动游戏。

 

奶牛们在一个长度为 M 的环形跑道上,从同一位置开始奔跑。

 

游戏共进行 N 轮,期间需要使用一副 8N 张牌,每张牌上写有数字 Xi

 

每轮游戏,约翰都会将最上面的 8 张牌移到单独的一堆中,并选择前 4 张或后 4 张牌供贝茜使用。

 

然后,贝茜在约翰选定的 4 张牌中,选择前 2 张牌或后 2 张牌。

 

在这之后,约翰喊出所选两张牌中,前 1 张牌上的数字 Xtop,接着奶牛们需要跑动 R×Xtop 的距离,其中 R 是到目前为止奶牛已经奔跑的总距离。

 

然后,贝茜喊出后 1 张牌上的数字 Xbottom,接着奶牛们需要跑动 Xbottom 的距离。

 

约翰担心,运动结束后,如果奶牛们走得太远,它们将太累而无法回到赛道的起点。

 

他认为,如果奶牛们在游戏结束时与起始位置的距离超过 K,它们将无法回家。

 

可以保证,只要约翰选择正确的游戏策略,无论贝茜采取什么行动,他将始终能够确保奶牛们可以回家。

 

对于每一轮游戏,你需要确定约翰应该选择哪一半的牌,从而使得无论贝茜从这一刻开始做出哪些选择,他总是可以让奶牛回家。

 

在输入中,会给出贝茜每轮的选择,以使你可以继续进行下一轮判断。

 

请注意,即使在输入中提供了贝茜的选择,你仍然需要指定约翰的选择,使得无论贝茜的选择是怎样的,约翰的选择都能够确保起到作用(毕竟,事实上约翰并不清楚贝茜在每一轮中会做出何种选择)。


输入格式

第一行包含三个整数 N,M,K

 

第二行包含一个长度为 N 的字符串,如果第 i 个字符是 T,表示在第 i 轮,贝茜会选择前两张卡牌,如果第 i 个字符是 B,表示在第 i 轮,贝茜会选择后两张卡牌。

 

接下来 N 行,每行包含 8 个整数,按顺序表示在一轮中拿出的从上到下的 8 张牌。

输出格式

输出一个长度为 N 的字符串,其中第 i 个字符是 T,表示在第 i 轮,约翰应选择前四张卡牌,如果第 i 个字符是 B,表示在第 i 轮,约翰应选择后四张卡牌。

 

如果答案不唯一,则输出字典序最小的字符串。

输入样例 复制

2 2 0
TT
1 0 0 0 0 0 0 1
0 1 1 1 0 0 1 0

输出样例 复制

TB

数据范围与提示

 

数据范围

2M109,

1N14,

0Xi<M,

0Kfloor(M/2)



样例解释

奶牛们必须最终恰好停在出发点上,才能回家。

 

注意,约翰预先并不知道贝茜会做出如何哪些选择。

 

如果约翰能够预先知道这些,那么他就会选择两次都取后一半。