NC222494. [USACOFeb2020B]MadScientist
描述
输入描述
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 B into A.
示例1
输入:
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.C++(g++ 7.5.0) 解法, 执行用时: 3ms, 内存消耗: 480K, 提交时间: 2023-03-05 15:43:23
#include <bits/stdc++.h> #define int long long #define cl(arr) memset(arr,0,sizeof arr) using namespace std; const int N=1e5+10; int n,m,k,q,ans,mx,r; // int a[N][N],dp[N][N]; int dx[4]={-1,1,0,0},dy[4]={0,0,1,-1}; int x[N],y[N]; void solve() { cin>>n; string s1,s2; cin>>s1>>s2; for(int i=0;i<n;i++){ if(s1[i]!=s2[i]&&s1[i+1]==s2[i+1]) ans++; } cout<<ans; return; } signed main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int t; // cin>>t; t=1; while(t--) solve(); return 0; } /* */
C++(clang++ 11.0.1) 解法, 执行用时: 2ms, 内存消耗: 400K, 提交时间: 2023-08-07 11:27:49
#include<bits/stdc++.h> using namespace std; int n,ans; char AA[1010],BB[1010]; int main(){ cin>>n; cin>>AA>>BB; for(int i=0;i<n;i++){ if(AA[i]!=BB[i]){ if(AA[i+1]==BB[i+1])ans++; } } cout<<ans; }