COW

时间限制: 1 Sec  内存限制: 64 MB
提交: 41  解决: 18
[提交][状态][讨论版]

题目描述

Bessie
the cow has stumbled across an intriguing inscription carved into a
large stone in the middle of her favorite grazing field. The text of the
inscription appears to be from a cryptic ancient language involving an
alphabet with only the three characters C, O, and W. Although Bessie
cannot decipher the text, she does appreciate the fact that C, O, and W
in sequence forms her favorite word, and she wonders how many times COW
appears in the text.

Bessie doesn't mind if there are other
characters interspersed within COW, only that the characters appear in
the correct order. She also doesn't mind if different occurrences of COW
share some letters. For instance, COW appears once in CWOW, twice in
CCOW, and eight times in CCOOWW.

Given the text of the inscription, please help Bessie count how many times COW appears.

输入

The
first line of input consists of a single integer N <= 10^5. The
second line contains of a string of N characters, where each character
is either a C, O, or W.

输出

 Output the number of times COW appears as a subsequence, not necessarily contiguous, of the input string.

Note that the answer can be very large, so
make sure to use 64 bit integers ("long long" in C++, "long" in Java)
to do your calculations.

样例输入

6
COOWWW

样例输出

6
【分析】模拟一下就行了
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include<functional>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
const int N=;
const int M=;
char s[N];
int n,m;
ll sc=,sco=,scow=;
int main(){
scanf("%d%s",&n,s);
for(int i=;i<n;i++){
if(s[i]=='C')sc++;
if(s[i]=='O')sco+=sc;
if(s[i]=='W')scow+=sco;
}
printf("%lld\n",scow);
return ;
}
												

COW的更多相关文章

  1. POJ 3278 Catch That Cow(bfs)

    传送门 Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 80273   Accepted: 25 ...

  2. 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心

    SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...

  3. HDU Cow Sorting (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1  ...

  4. [BZOJ1604][Usaco2008 Open]Cow Neighborhoods 奶牛的邻居

    [BZOJ1604][Usaco2008 Open]Cow Neighborhoods 奶牛的邻居 试题描述 了解奶牛们的人都知道,奶牛喜欢成群结队.观察约翰的N(1≤N≤100000)只奶牛,你会发 ...

  5. 细读cow.osg

    细读cow.osg 转自:http://www.cnblogs.com/mumuliang/archive/2010/06/03/1873543.html 对,就是那只著名的奶牛. //Group节点 ...

  6. POJ 3176 Cow Bowling

    Cow Bowling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13016   Accepted: 8598 Desc ...

  7. raw,cow,qcow,qcow2镜像的比较

    在linux下,虚拟机的选择方式有很多,比如vmware for linux,virtual box,还有qemu,在以前,使用qemu的人不多,主要是使用起来有些麻烦,但现在随着Openstack的 ...

  8. poj1985 Cow Marathon (求树的直径)

    Cow Marathon Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 3195   Accepted: 1596 Case ...

  9. (01背包变形) Cow Exhibition (poj 2184)

    http://poj.org/problem?id=2184   Description "Fat and docile, big and dumb, they look so stupid ...

  10. 图论 ---- spfa + 链式向前星 ---- poj 3268 : Silver Cow Party

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12674   Accepted: 5651 ...

随机推荐

  1. 【算法】高斯消元&线性代数

    寒假作业~就把文章和题解3道题的代码扔在这里啦——链接: https://pan.baidu.com/s/1kWkGnxd 密码: bhh9 1.HNOI2013游走 #include <bit ...

  2. More on understanding sort_buffer_size

    There have been a few posts by Sheeri and Baron today on the MySQL sort_buffer_size variable. I want ...

  3. jquery中:input和input的区别

    :input表示选择表单中的input,select,textarea,button元素, input仅仅选择input元素. <button>和<input type=" ...

  4. vue与node模版引擎的渲染标记{{}}(双花括号)冲突

    由于之前练习koa2,直接渲染的jquery写的传统页面. 这次想偷懒,直接script引入vue,发现渲染不出data值. 渲染引擎用得是xtpl, 找了半天没有发现可以修改xtpl渲染分隔符的配置 ...

  5. ES6学习笔记(三)—— Set 和 Map

    SetES6提供的数据结构,类似于数组,但是成员的值都是唯一的.(提供了一种数组去重的方法) Set 内部判断两个值是否相同使用的是 'Same-value equality',类似于 ===但是 N ...

  6. DOM 2

    1.对文档的信息进行检索常用的方法: getElementById; getElementsByTagName; getAttribute;//得到的是属性值 2把需要的信息添加到DOM中常用的方法: ...

  7. cxf+spring发布webservice和调用

    maven项目配置http://cxf.apache.org/docs/using-cxf-with-maven.html <properties> <cxf.version> ...

  8. 51Nod 2006 飞行员配对(二分图最大匹配)-匈牙利算法

    2006 飞行员配对(二分图最大匹配) 题目来源: 网络流24题 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 第二次世界大战时期,英国皇家空军从沦陷国 ...

  9. Spring - IoC(12): 属性占位符

    使用属性占位符可以将 Spring 配置文件中的部分元数据放在属性文件中设置,这样可以将相似的配置(如 JDBC 的参数配置)放在特定的属性文件中,如果只需要修改这部分配置,则无需修改 Spring ...

  10. 【2016-09-27-DP小练】

    得分250..我真是个250... 犯了一些很搞笑的错.. f[i][j][k]表示第i个苹果,现在在j这个位置,还能用k次转移. 用i去更新i+1. 时间复杂度1000*2*30: 转移方程有个地方 ...