CF132C.Logo Turtle

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward").

You are given a list of commands that will be given to the turtle. You have to change exactly n commands from the list (one command can be changed several times). How far from the starting point can the turtle move after it follows all the commands of the modified list?

许多人将 Logo 编程语言与海龟绘图(turtle graphics)联系在一起。在本题中,海龟沿直线移动,并接受两种命令:“T”(“掉头”)和“F”(“向前移动 1 个单位”)。

你将获得一个命令列表,这些命令将被依次交给海龟执行。你必须恰好修改列表中的 n 个命令(同一个命令可被多次修改)。在海龟执行完修改后的全部命令后,它距离起点最远可能达到多远?

输入格式

The first line of input contains a string commands — the original list of commands. The string commands contains between 1 and 100 characters, inclusive, and contains only characters "T" and "F".

The second line contains an integer n (1 ≤ n ≤ 50) — the number of commands you have to change in the list.

输入的第一行包含一个字符串 commands —— 原始的命令列表。字符串 commands 的长度在 1 到 100 之间(含端点),且仅由字符 "T" 和 "F" 组成。

第二行包含一个整数 n(1 ≤ n ≤ 50)—— 你需要在该命令列表中修改的命令数量。

输出格式

Output the maximum distance from the starting point to the ending point of the turtle's path. The ending point of the turtle's path is turtle's coordinate after it follows all the commands of the modified list.

输出乌龟路径起点到终点的最大距离。乌龟路径的终点是乌龟执行修改后的指令列表中所有命令后所处的坐标。

输入输出样例

  • 输入#1

    FT
    1

    输出#1

    2
  • 输入#2

    FFFTFFF
    2

    输出#2

    6

说明/提示

In the first example the best option is to change the second command ("T") to "F" — this way the turtle will cover a distance of 2 units.

In the second example you have to change two commands. One of the ways to cover maximal distance of 6 units is to change the fourth command and first or last one.

在第一个例子中,最优方案是将第二个命令(“T”)改为“F”——这样海龟将行进 2 个单位的距离。

在第二个例子中,您需要修改两条命令。一种能够实现最大行进距离(6 个单位)的方法是修改第四条命令以及第一条或最后一条命令。

输入解题思路,AI测评打分。不知道怎么写?

首页