CF74B.Train
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A stowaway and a controller play the following game.
The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or idle. Every minute the players move.
The controller's move is as follows. The controller has the movement direction — to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the n-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move.
The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of n wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back.
Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train.
If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again.
At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner.
一名逃票者与一名列车员进行如下游戏。
列车由 n 节车厢组成,车厢从车头到车尾依次用正整数 1 至 n 编号。逃票者与列车员初始时分别位于两个不同的车厢中。每分钟,列车处于两种状态之一:运行中或静止(停站)。每分钟双方均执行一次移动。
列车员的移动规则如下:
列车员具有一个固定的移动方向——朝向车头(即编号减小的方向)或朝向车尾(即编号增大的方向)。在每次移动中,列车员沿其当前方向移至相邻车厢。若在其移动结束时进入第 1 节或第 n 节车厢,则立即将移动方向反转为另一方向。换言之,列车员在整个游戏过程中持续地、周期性地从车头走向车尾、再从车尾返回车头,每步恰好移动一节车厢。注意,列车员在任意时刻有且仅有一种合法移动。
逃票者的移动规则取决于列车状态:
- 若列车正在运行,则逃票者可选择移至其中一个相邻车厢,或原地不动;
- 若列车停靠在车站且处于静止状态,则逃票者先离开列车(即此时他不再位于任何车厢中);随后,若该车站不是终点站,他可重新进入列车,并自由选择任意一节车厢(共 n 节)上车(不必是刚刚离开的那一节,也不必是相邻车厢)。若列车连续多分钟处于静止状态,则每一分钟均重复该过程:先下车,再(如非终点站)上车。
双方移动顺序规定如下:
- 若当前分钟列车正在运行,则先由逃票者移动,再由列车员移动;
- 若当前分钟列车静止(停站),则先由逃票者下车,再由列车员移动,最后由逃票者上车(若非终点站)。
若在某一时刻,逃票者与列车员位于同一节车厢,则列车员获胜:他将对逃票者处以罚款。
若在某次移动后,逃票者抵达终点站,则逃票者获胜:他直接在该次移动中离开车站,且永不返回。
在任意时刻,双方均知晓彼此的当前位置。双方均采取最优策略进行游戏。具体而言:
- 若列车员最终获胜,则逃票者将尽力最大化失败所需的时间(即尽可能延迟被抓住);
- 由于列车员的所有可能移动均唯一确定,因此他天然始终采取最优策略。
请判断游戏的获胜方。
输入格式
The first line contains three integers n, m and k. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2 ≤ n ≤ 50, 1 ≤ m, k ≤ n, m ≠ k).
The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon n is the tail.
The third line has the length from 1 to 200 and consists of symbols "0" and "1". The i-th symbol contains information about the train's state at the i-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" — that's the terminal train station.
第一行包含三个整数 n、m 和 k,分别表示列车的车厢数量、逃票者和检票员的初始位置(2≤n≤50,1≤m,k≤n,且 m=k)。
第二行给出检票员移动的方向。“to head” 表示检票员向列车车头方向移动,“to tail” 表示检票员向列车车尾方向移动。保证检票员所移动的方向上至少存在一节车厢。车厢 1 为车头,车厢 n 为车尾。
第三行长度为 1 至 200,仅由字符 “0” 和 “1” 组成。其中第 i 个字符描述列车在第 i 分钟的状态:“0” 表示该分钟列车正在运行,“1” 表示该分钟列车处于静止状态。第三行的最后一个字符恒为 “1”——这代表终点站。
输出格式
If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught.
如果偷渡者获胜,输出 "Stowaway"(不带引号)。否则,再次输出 "Controller"(不带引号),然后在空格后输出偷渡者将被抓获的分钟数。
输入输出样例
输入#1
5 3 2 to head 0001001
输出#1
Stowaway
输入#2
3 2 1 to tail 0001
输出#2
Controller 2
输入解题思路,AI测评打分。不知道怎么写?