欢迎光临散文网 会员登陆 & 注册

CF 1779A - Hall of Fame

2023-07-18 14:54 作者:您是打尖儿还是住店呢  | 我要投稿

Thalia is a Legendary Grandmaster in chess. She has n trophies in a line numbered from 1 to n (from left to right) and a lamp standing next to each of them (the lamps are numbered as the trophies).

A lamp can be directed either to the left or to the right, and it illuminates all trophies in that direction (but not the one it is next to). More formally, Thalia has a string s consisting only of characters 'L' and 'R' which represents the lamps' current directions. The lamp i illuminates:

trophies 1,2,…,i−1 if si is 'L';trophies i+1,i+2,…,n if si is 'R'.

She can perform the following operation at most once:


Choose an index i (1≤i<n);Swap the lamps i and i+1 (without changing their directions). That is, swap si with si+1.

Thalia asked you to illuminate all her trophies (make each trophy illuminated by at least one lamp), or to tell her that it is impossible to do so. If it is possible, you can choose to perform an operation or to do nothing. Notice that lamps cannot change direction, it is only allowed to swap adjacent ones.

----------------------------------------------------------

塔利亚是一位传奇的国际象棋大师。 她有 n 个奖杯,排成一排,编号从 1 到 n(从左到右),每个奖杯旁边都立着一盏灯(灯被编号为奖杯)。

一盏灯可以指向左侧或右侧,它会照亮该方向上的所有奖杯(但不会照亮旁边的奖杯)。 更正式地说,Thalia 有一个仅由字符“L”和“R”组成的字符串 s,表示灯的当前方向。 灯 i 亮起:

如果 si 为“L”,则奖杯 1,2,…,i−1;如果 si 为“R”,则奖杯 i+1,i+2,…,n。

她最多可以执行一次以下操作:


选择一个索引i(1≤i<n);交换灯i和i+1(不改变它们的方向)。 即,将si 与si+1 交换。

塔莉亚要求你照亮她所有的奖杯(让每个奖杯至少被一盏灯照亮),或者告诉她这是不可能的。 如果可能,您可以选择执行操作或不执行任何操作。 请注意,灯不能改变方向,只能交换相邻的灯。

-------------------------------------------

substring卡了下,啊,我的脑仁啊。。。


CF 1779A - Hall of Fame的评论 (共 条)

分享到微博请遵守国家法律