Mad Scientist (纯模拟题)

简介: Mad Scientist题目描述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.

Mad Scientist


题目描述


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.


输入


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.

输出


Print the minimum number of times the machine needs to be applied to transform BB into AA.

样例输入


7
GHHHGHH
HHGGGHH


样例输出


2


提示


First, FJ can transform the substring that corresponds to the first character alone, transforming B into GHGGGHH. Next, he can transform the substring consisting of the third and fourth characters, giving A. Of course, there are other combinations of two applications of the machine that also work.


这道题的题目意思是:有两个字符串下面的字符串,每次可以选择连续的或者是单个的字符进行变换,求由下面的这个字符串变换到上面的字符串最小的操作的次数是多少


题目挺水的直接上代码

虽然我的代码有点丑,用的方法还是比较麻烦,欢迎批评改进!!!


#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
//#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
#define read read()
const ll inf = 1e15;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
#define start int wuyt()
#define end return 0
char ss1[maxn],ss2[maxn];
int judge[maxn];
start{
    int n=read;
    scanf("%s",ss1+1);
    scanf("%s",ss2+1);
    for(int i=1;i<=n;i++)
    {
        if(ss1[i]!=ss2[i]) judge[i]=0;
        else if(ss1[i]==ss2[i]) judge[i]=1;
    }
    judge[0]=2;
    int asn=0;
    for(int i=1;i<=n;i++)
    {
        if(judge[i]==0&&judge[i-1]!=0)
        {
            asn++;
        }
    }
    cout<<asn;
  end;
}


目录
相关文章
|
11月前
|
存储 C++
【PAT甲级 - C++题解】1056 Mice and Rice
【PAT甲级 - C++题解】1056 Mice and Rice
39 0
[ICPC 46th Shanghai] Life is a Game 克鲁斯卡尔重构树
题目大意: 给定n个点,m条边,有q个询问 每个点有一个(能量值)点权,每条边有一个边权 m条边描述为u v w表示有一条u与v相连的边权为w的通路 在每一次询问中,给定一个点x和现有的能量值k,每次只能是在当前能量值大于边权的时候到达另一个点,并获取这个点的能量值(路可以重复走),问最终能够获得多大的能量值
102 0
|
人工智能 BI
[UVA 1599] Ideal Path | 细节最短路
Description New labyrinth attraction is open in New Lostland amusement park. The labyrinth consists of n rooms connected by m passages. Each passage is colored into some color ci .
176 0
|
机器学习/深度学习 物联网
[Codeforces 1586] Omkar and Determination | 思维前缀和
题意 给定一个n ∗ m 的方格,在这个方格中有一些点被标记为′ . ′ 说明这个点是没有障碍的,而′ X ′ 代表这个点是有障碍的,不能通过这个点,对于每个点,只能向上或者是向左走。如所说有的′ . ′ 点不能走出去,那么这样的′ . ′ 点就不是e x i t a b l e exitable 问题是:给定一个矩阵里面所有的 exitable点,如果给出的矩阵能够唯一确定,就是YES,否则输出 NO 所以问题就变成了给定的矩阵范围中有没有是′ . ′但是不能够 exitable的点,如果有就无法唯一确定(YES),反之就可以唯一确定(NO) 数据范围太大,可以开 vector 来模拟二维数
560 0
POJ-1328,Radar Installation(贪心)
POJ-1328,Radar Installation(贪心)
|
人工智能 Java
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem E. Sequence
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem E. Sequence
125 0
|
人工智能 Java
HDU - 2018杭电ACM集训队单人排位赛 - 4 - Problem C. Sequence
HDU - 2018杭电ACM集训队单人排位赛 - 4 - Problem C. Sequence
86 0
|
Java
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem F. Four-tuples
HDU - 2018杭电ACM集训队单人排位赛 - 3 - Problem F. Four-tuples
117 0
|
Java Go
HDU - 2018杭电ACM集训队单人排位赛 - 2 - Problem E. Travel
HDU - 2018杭电ACM集训队单人排位赛 - 2 - Problem E. Travel
97 0