QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#20960. 疯狂科学家

Statistics

Farmer John 的表亲 Ben 恰好是一位疯狂科学家。通常这会在家庭聚会上引起不少摩擦,但偶尔也会有所帮助,尤其是在 Farmer John 遇到有关奶牛的独特而不寻常的问题时。

Farmer John 现在就面临着这样的问题。他最近订购了 $N$ 头奶牛($1 \leq N \leq 1000$),有 Holstein 和 Guernsey 两个品种。他用一个长度为 $N$ 的字符串指定订单中奶牛的品种,每个字符为 $H$(Holstein)或 $G$(Guernsey)。遗憾的是,奶牛到达农场并排成一队时,品种构成的字符串与原来的不同。

将这两个字符串称为 $A$ 和 $B$,其中 $A$ 是 Farmer John 原本想要的品种标识字符串,$B$ 是奶牛到达时看到的字符串。Farmer John 没有简单地检查重排 $B$ 中的奶牛是否足以得到 $A$,而是请表亲 Ben 用科学才智帮他解决问题。

经过几个月,Ben 创造了一台非凡的机器 multi-cow-breed-flipinator 3000,可以选取任意一段连续的奶牛并切换品种:这段中的所有 $H$ 变为 $G$,所有 $G$ 变为 $H$。Farmer John 想知道将当前顺序 $B$ 变为最初想要的顺序 $A$,最少需要使用多少次机器。遗憾的是,Ben 的疯狂科学家技能只擅长制造巧妙的装置,因此需要你帮 Farmer John 解决这一计算难题。

输入格式

输入的第一行包含 $N$,接下来两行包含字符串 $A$ 和 $B$。每个字符串有 $N$ 个字符,均为 $H$ 或 $G$。

输出格式

输出将 $B$ 变为 $A$ 所需使用机器的最少次数。

样例

输入格式 1

7
GHHHGHH
HHGGGHH

输出格式 1

2

说明

首先,FJ 可以翻转仅包含第一个字符的子串,将 $B$ 变为 GHGGGHH。随后,他可以翻转第三、第四个字符组成的子串,得到 $A$。当然,也存在其他使用两次机器的有效组合。

题目作者:Brian Dean

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.