ACWing--寒假每日一题代码笔记(1.1)

4993. FEB--(python)

4993. FEB - AcWing题库

n= int(input())
# print(n)
s=list(input())
# print(n)
# 情况一:
# xxxxxx

# 合并两个公差为2的等差数列 公差仍为 2 
# 合并公差分别为1和2 的等差数列 公差为1
if (s.count('F')==n):
    print(n)
    for i in range (n):
        print(i)
else:
    # 左右边界
    l,r=0,n-1
    # print(s[r])
    # 找到不为f开头,不为F结尾的位置
    while(s[l]=='F'): l+=1
    while(s[r]=='F'): r-=1
    # print(l,r)
    # 最小和最大
    low,high=0,0
    # 复制s
    s1=s[:]
    for i in range (l,r+1):
        if(s1[i]=='F'):
            if(s1[i-1]=='B'):s1[i]='E'
            else: s1[i]='B'
        # 贪心
        if (i>l and s1[i]==s1[i-1]):
            low+=1
    
    s1=s[:]
    for i in range (l,r+1):
        if s1[i]=='F':s1[i]=s1[i-1]
        if (i>l and s1[i]==s1[i-1]):
            high+=1
    # print(s1)
    # 左右两边F的数量 
    ends=l+n-1-r
    # 公差是2
    d=2
    if (ends):
        high+=ends
        d=1
    # print(f'{high} {low}')
    # print(d)
    # 等差数列求项公式
    print(int((high-low)/d+1))
    # print(int(2/3))
    for i in range(low,high+1,d):
        print(i)



你可能感兴趣的:(ACWing,笔记,python,算法)