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.