• 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.
    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.

    这道题的题目意思是:有两个字符串下面的字符串,每次可以选择连续的或者是单个的字符进行变换,求由下面的这个字符串变换到上面的字符串最小的操作的次数是多少
    当读相信诸位大佬懂题目意思时就知道是道水题了
    本蒟蒻写这篇博客的动机就是为了纪念因为自己太菜而晚交了2min导致每道题没有交上,很是后悔(看来以后吃饭要抓紧时间了)

    题目挺水的直接上代码
    虽然我的代码有点丑,用的方法还是比较麻烦,欢迎批评改进!!!

    #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;
    }
    
    
  • 相关阅读:
    setTimeout和setInterval的区别(面试题)
    什么是跨域?列出几种JS跨域解决方法?(前端面试题)
    建网站的流程
    CSS Sprite(雪碧图)简单使用
    前端不得不说的性能优化
    面试题
    前端如何做好SEO优化
    JavaScript string字符串对象常见方法
    微信号复制跟跳转——clipboard.js
    微信号复制跟跳转——execCommand()
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13144221.html
Copyright © 2020-2023  润新知