1672. 疯狂的科学家

摘要
Title: 1672. 疯狂的科学家
Tag: 贪心
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

1672. 疯狂的科学家

  • 题意

    img

  • 思路

    贪心即可,从头开始贪,遇到连续的翻转翻就行

  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    '''
    Author: NEFU AB-IN
    Date: 2022-02-15 14:25:51
    FilePath: \ACM\Acwing\1672.py
    LastEditTime: 2022-02-15 14:29:44
    '''
    if __name__ == "__main__":
    n = int(input())
    a = input()
    b = input()

    flag = 0 #处于不反转状态
    res = 0
    for i in range(n):
    if b[i] != a[i] and flag == 0:
    flag = 1
    res += 1
    elif b[i] == a[i] and flag == 1:
    flag = 0
    print(res)
使用搜索:谷歌必应百度