翻硬币

翻硬币

先手动模拟一遍过程,会发现解是具有唯一性的。

所以 唯一解就是最小步数,\(O(n)\) ,直接扫一遍就好了

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long LL;
typedef pair<int,int> PII;
const int N = 110;
char str[N],endi[N];
void turn(int x) {
    if(str[x] == '*') str[x] = 'o';
    else str[x] = '*';
}
int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> str >> endi;
    int len = strlen(str);
    int res = 0;
    for(int i = 0;i < len - 1; ++i) {
        if(str[i] != endi[i]) {
            res ++;
            turn(i);
            turn(i + 1);
        }
    }
    cout << res << endl;
    return 0;
}
posted @ 2020-01-23 13:37  lukelmouse  阅读(199)  评论(1编辑  收藏  举报