A289.[ USACO 2020 February Bronz]Mad Scientist

普及/提高-

USACO

通过率:0%

时间限制:1.00s

内存限制:128MB

题目描述

Farmer John's cousin Ben happens to be a mad scientist. Normally, this creates a good bit of friction at family gatherings, but it can occasionally be helpful, especially when Farmer John finds himself facing unique and unusual problems with his cows.
Farmer John is currently facing a unique and unusual problem with his cows. He recently ordered N cows (1≤N≤1000) consisting of two different breeds: Holsteins and Guernseys. He specified the cows in his order in terms of a string of N characters, each either H (for Holstein) or G (for Guernsey). Unfortunately, when the cows arrived at his farm and he lined them up, their breeds formed a different string from this original string.

Let us call these two strings A and B, where A is the string of breed identifiers Farmer John originally wanted, and B is the string he sees when his cows arrive. Rather than simply check if re-arranging the cows in B is sufficient to obtain A, Farmer John asks his cousin Ben to help him solve the problem with his scientific ingenuity.

After several months of work, Ben creates a remarkable machine, the multi-cow-breed-flipinator 3000, that is capable of taking any substring of cows and toggling their breeds: all Hs become Gs and all Gs become Hs in the substring. Farmer John wants to figure out the minimum number of times he needs to apply this machine to transform his current ordering B into his original desired ordering A. Sadly, Ben's mad scientist skills don't extend beyond creating ingenious devices, so you need to help Farmer John solve this computational conundrum.

INPUT FORMAT :
The first line of input contains N, and the next two lines contain the strings A and B. Each string has N characters that are either H or G.
OUTPUT FORMAT:
Print the minimum number of times the machine needs to be applied to transform B into A.

Farmer John 的远房亲戚 Ben 是一个疯狂的科学家。通常这会在家庭聚会时造成不小的摩擦,但这偶尔也会带来些好处,尤其是当 Farmer John 发现他正面对一些有关他的奶牛们的独特而不寻常的问题时。

Farmer John 当前正面对一个有关她的奶牛们的独特而不寻常的问题。他最近订购了 NN 头奶牛(1N10001\le N\le1000),包含两种不同品种:荷斯坦牛和更赛牛。他在订单中用一个长为 NN 的字符串来指定奶牛,其中的字符为$ H$(表示荷斯坦牛)或 GG(表示更赛牛)。

不幸的是,当这些奶牛到达他的农场,他给她们排队时,她们的品种组成的字符串与原先的不同。
我们将这两个字符串称为 AABB,其中 AA 是 Farmer John 原先想要的品种字符组成的字符串,BB 是他的奶牛们到达时组成的字符串。

Farmer John 并没有简单地检查重新排列 BB 中的奶牛是否能得到 AA,而是请他的远房亲戚 Ben 利用他的科学才华来解决这一问题。

经过数月的研究,Ben 发明了一台不同寻常的机器:奶牛品种转换机30003000,能够选择任意奶牛组成的子串并反转她们的品种:在这个子串中的所有 HH 变为 GG,所有 GG 变为 HH

Farmer John 想要求出将他当前的序列$ B$ 变为他本来订购时想要的 AA 需要使用这台机器的最小次数。然而,Ben 的疯狂的科学家技能并不会处理开发奇异机器以外的事,所以你需要帮助 Farmer John 解决这个计算难题。

输入格式

输入的第一行包含 NN,以下两行包含字符串 AABB。每个字符串均包含 NN 个字符,字符均为 HHGG 之一。

输出格式

输出将 BB 变为 AA 需要使用机器的最小次数。

输入输出样例

  • 输入#1

    7
    GHHHGHH
    HHGGGHH

    输出#1

    2

说明/提示

首先,FJ 可以仅改变第一个字符组成的子串,将 BB 变为 GHGGGHHGHGGGHH。然后,他可以改变由第三和第四个字符组成的子串,得到 AA。当然,还存在其他有效的执行两次操作的方案。

首页