首页 > 其他 > 详细

翻硬币

时间:2020-01-23 14:09:43      阅读:75      评论:0      收藏:0      [点我收藏+]

翻硬币

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

所以 唯一解就是最小步数,\(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;
}

翻硬币

原文:https://www.cnblogs.com/lukelmouse/p/12230530.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!