AcWing 1208. 翻硬币
原题链接
简单
题目的意思是必修同时俩,所以删掉k操作就行
#include<cstring>
#include<iostream>
using namespace std;
string start, en;
int dx[] = {-1, 0}, l;
void turn(int x) {
for(int i = 0; i < 2; i ++) {
int a = x + dx[i];
if(a >= 0 && a < l)
start[a] = (start[a] == '*') ? 'o' : '*';
}
}
int work() {
int ans = 1e6;
string backup = start;
int res = 0;
for(int i = 0; i < l; i ++) {
if(start[i] != en[i]) {
turn(i + 1);
res ++;
}
}
start = backup;
if(start[l - 1] == en[l - 1]) ans = min(ans, res);
return ans;
}
int main() {
cin >> start >> en;
l = start.length();
cout << work() << endl;
return 0;
}