A881 | Photoshoot--Bronze
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Farmer John, desperate to win the award for best cow photographer at the
county fair, is trying to take the perfect photograph of his $N$ cows ($2 \leq
N \leq 2\cdot 10^5$, $N$ even).
Farmer John owns cows of two potential breeds: Guernseys and Holsteins. To
make his photo as aesthetic as possible, he wants to line up his cows so that
as many Guernseys are in even-numbered positions in the line as possible (the
first position in the line is an odd position, the next is an even position,
and so on). Due to his lack of strong communication with his cows, the only
way he can achieve his goal is by asking even length "prefixes" of his cows to
reverse themselves (a prefix consists of the range of cows from the first cow
up to the $j$th cow for some position $j$).
Please count the minimum number of reversals required for Farmer John to
achieve his goal.
county fair, is trying to take the perfect photograph of his $N$ cows ($2 \leq
N \leq 2\cdot 10^5$, $N$ even).
Farmer John owns cows of two potential breeds: Guernseys and Holsteins. To
make his photo as aesthetic as possible, he wants to line up his cows so that
as many Guernseys are in even-numbered positions in the line as possible (the
first position in the line is an odd position, the next is an even position,
and so on). Due to his lack of strong communication with his cows, the only
way he can achieve his goal is by asking even length "prefixes" of his cows to
reverse themselves (a prefix consists of the range of cows from the first cow
up to the $j$th cow for some position $j$).
Please count the minimum number of reversals required for Farmer John to
achieve his goal.
输入格式
The first line of input contains the value of $N$.
The second line contains a string of length $N,$ specifying the initial
ordering of the cows from left to right. Each 'H' represents a Holstein, while
each 'G' represents a Guernsey.
The second line contains a string of length $N,$ specifying the initial
ordering of the cows from left to right. Each 'H' represents a Holstein, while
each 'G' represents a Guernsey.
输出格式
Output the minimum number of reversals needed on a single line.
输入输出样例
输入 #1
14 GGGHGHHGHHHGHG
输出 #1
1
In this example, it suffices to reverse the prefix consisting of the first six
cows.
GGGHGHHGHHHGHG (Before)
-> HGHGGGHGHHHGHG (After)
Before the reversal, four Guernseys were at even positions. After the
reversal, six Guernseys are at even positions. It is impossible for there to
be more than six Guernseys at even positions.
cows.
GGGHGHHGHHHGHG (Before)
-> HGHGGGHGHHHGHG (After)
Before the reversal, four Guernseys were at even positions. After the
reversal, six Guernseys are at even positions. It is impossible for there to
be more than six Guernseys at even positions.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted