题目链接:Codeforces 399B Red and Blue Balls
题目大意:在一个竖着的盒子里,有若干个球,给出球都颜色。每次将最上面的蓝色球上面的红色球取出,然后将该蓝色球换成红色,上面补上蓝色球。问说最少要多少次操作可以使得全部球都是红色的。
解题思路:其实就是一个二进制数,注意要用long long。
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 60;
ll t = 1;
int main () {
int n;
char str[N];
scanf("%d%s", &n, str);
ll ans = 0;
for (int i = 0; i < n; i++) if (str[i] == 'B') {
ans += (t<<i);
}
cout << ans << endl;
return 0;
}