AC日记——Red and Blue Balls codeforces 399b

399B - Red and Blue Balls

思路:

  惊讶的发现,所有的蓝球的消除都是独立的;

  对于在栈中深度为i的蓝球消除需要2^i次操作;

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

long long ans=0;

int main()
{
//    freopen("ball.in","r",stdin);
//    freopen("ball.out","w",stdout);
    int n;char ch[105];
    long long count=1;
    scanf("%d",&n);
    scanf("%s",ch);
    for(int i=0;i<n;i++)
    {
        if(ch[i]=='B') ans+=count;
        count<<=1;
    }
    printf("%lld
",ans);
    return 0;
}
原文地址:https://www.cnblogs.com/IUUUUUUUskyyy/p/6912744.html