399B - Red and Blue Balls

思路:

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

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

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; long long ans=; int main()
{
// freopen("ball.in","r",stdin);
// freopen("ball.out","w",stdout);
int n;char ch[];
long long count=;
scanf("%d",&n);
scanf("%s",ch);
for(int i=;i<n;i++)
{
if(ch[i]=='B') ans+=count;
count<<=;
}
printf("%lld\n",ans);
return ;
}

AC日记——Red and Blue Balls codeforces 399b的更多相关文章

  1. codeforces 399B. Red and Blue Balls 解题报告

    题目链接:http://codeforces.com/problemset/problem/399/B 题目意思:给出 n 个只由 R 和 B 组成的字符串(由上到下排列,相当于栈),问最多可以操作多 ...

  2. Codeforces Round #233 (Div. 2) B. Red and Blue Balls

    #include <iostream> #include <string> using namespace std; int main(){ int n; cin >&g ...

  3. cf B Red and Blue Balls

    思路:把字符串转化为一个二进制,遇到B就是一个数二进制中的1,答案就是这个数. #include <cstdio> #include <cstring> #include &l ...

  4. AC日记——Sagheer and Nubian Market codeforces 812c

    C - Sagheer and Nubian Market 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #defin ...

  5. AC日记——Andryusha and Colored Balloons codeforces 780c

    C - Andryusha and Colored Balloons 思路: 水题: 代码: #include <cstdio> #include <cstring> #inc ...

  6. AC日记——Little Elephant and Shifts codeforces 221e

    E - Little Elephant and Shifts 思路: 一次函数线段树(疯狂debug): b不断循环左移,判断每次最小的|i-j|,a[i]=b[j]: 仔细观察发现,每个bi移动时, ...

  7. AC日记——Little Elephant and Problem codeforces 221c

    221C 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> #include ...

  8. AC日记——Little Elephant and Array codeforces 221d

    221D - Little Elephant and Array 思路: 莫队: 代码: #include <cmath> #include <cstdio> #include ...

  9. AC日记——Little Elephant and Numbers codeforces 221b

    221B - Little Elephant and Numbers 思路: 水题: 代码: #include <cmath> #include <cstdio> #inclu ...

随机推荐

  1. Activiti工作流(三)——流程变量

    流程变量可以是流程中一系列参数,比如办理人(Assignee),消息(message)等.这些流程变量使得activiti能够应用于更为复杂的业务中,使得流程变得更加灵活可控. 场景(一) 图一:没有 ...

  2. 【SSH】——hql的使用方式及实现原理

    [含义] hql,即Hibernate Query  Language.它与我们熟知的sql很类似,它最大的特点就是对查询进行了面向对象的封装,下面会在具体例子中说明. sql查询的是数据库中的表或字 ...

  3. DataView RowFilter Syntax [C#]

    RowFilter语法 private void btnEnquiry_Click(object sender, EventArgs e) { string filterExpression = st ...

  4. 【bzoj1951】[Sdoi2010]古代猪文 费马小定理+Lucas定理+中国剩余定理

    题目描述 求  $g^{\sum\limits_{k|n}C_{n}^{\frac nk}}\mod 999911659$ 输入 有且仅有一行:两个数N.G,用一个空格分开. 输出 有且仅有一行:一个 ...

  5. 【转】Win7装不上Office2010 提示MSXML 6.10.1129.0

    转自:http://zhidao.baidu.com/link?url=aZPbpBu0Fb7rc8HCb_NuonuZ4ET_BB8_NgZ96tCpB9dyuUyWVwMl78MLa7rh-rfx ...

  6. 【C++ troubleshooting】A case about decltype

    template <typename iter_t> bool next_permutation(iter_t beg, iter_t end) { // if (beg == end | ...

  7. bzoj2724: [Violet 6]蒲公英 分块 区间众数 论algorithm与vector的正确打开方式

    这个,要处理各个数的话得先离散,我用的桶. 我们先把每个块里的和每个块区间的众数找出来,那么在查询的时候,可能成为[l,r]区间的众数的数只有中间区间的众数和两边的数. 证明:若不是这里的数连区间的众 ...

  8. yum命令Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY

    yum命令Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY 博客分类: linux   三种解决方案 我采取第三种方案解决的 第一种: linu ...

  9. 通过init-connect + binlog 实现MySQL审计功能

    背景: 假设这么一个情况,你是某公司mysql-DBA,某日突然公司数据库中的所有被人为删了. 尽管有数据备份,但是因服务停止而造成的损失上千万,现在公司需要查出那个做删除操作的人. 但是拥有数据库操 ...

  10. LA2995 Image is everything

    蓝书P12 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm ...