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. Java基础——集合

    java的集合类是一个工具类,存放在java.util包中.它不仅可以存储对象,也可以实现常用数据结构,如栈.队列等.严格的说,集合类存放的是对象的引用,而不是对象本身. java集合主要由这两个接口 ...

  2. 【Linux】——实用命令

    [前言] Linux的命令可以分为文件存取.目录操作.进程管理.权限管理.磁盘操作等内容,大量的命令方便了用户进行更快捷更高效的工作.但有一点需要说明的是,如果不采用linux的命令,也可以完成相应的 ...

  3. intelliJ idea 使用技巧&方法

    导入的项目查看svn地址:在项目上右键--subversion--relocate可以看到以前对应的svn地址. 重要的几个快捷键的使用方式: (1)       alt+insert 成员变量封装 ...

  4. maven与gradle的对比

    Java世界中主要有三大构建工具:Ant.Maven和Gradle.经过几年的发展,Ant几乎销声匿迹.Maven也日薄西山,而Gradle的发展则如日中天.笔者有幸见证了Maven的没落和Gradl ...

  5. php spl库的使用(PHP标准库)【摘抄引用】

    文章来源与推荐阅读:阮一峰--PHP SPL笔记  &&  PHP SPL使用方法和他的威力 1.SPL 是什么? SPL:standard php library php标准库,此 ...

  6. 图论:Gale-Shapley算法

    Gale-Shapley算法又叫做延迟认可算法,它可以解决这么一个问题 一共有N位男士和N位女士 每位男士对每位女士都有一个好感度,让他们结合成为N对夫妻,要求男士优先表白,最后问结合情况 第一轮,每 ...

  7. 【SPOJ-QTREE3】树链剖分

    http://www.spoj.com/problems/QTREE3/ 时间限制:2s    代码长度限制:50000B     内存限制:1536MB [题目描述] 给出N个点的一棵树(N-1条边 ...

  8. swift中_的用法,忽略默认参数名。

    swift中默认参数名除了第一个之外,其他的默认是不忽略的,但是如果在参数的名字前面加上_,就可以忽略这个参数名了,虽然有些麻烦,但是这种定义也挺好,而且不想知道名字或者不想让别人知道名字的或者不用让 ...

  9. DotNETCore 学习笔记 日志

    Logging --------------------------------------------------------------------------------------- Impl ...

  10. keras_实现cnn_手写数字识别

    # conding:utf-8 import os os.environ[' import numpy as np from keras.models import Sequential from k ...