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. 2018牛客多校第一场 B.Symmetric Matrix

    题意: 构造一个n*n的矩阵,使得Ai,i = 0,Ai,j = Aj,i,Ai,1+Ai,2+...+Ai,n = 2.求种类数. 题解: 把构造的矩阵当成邻接矩阵考虑. 那么所有点的度数都为2,且 ...

  2. ARC076 F Exhausted? Hall定理 + 线段树扫描线

    ---题面--- 题目大意: 有n个人,m个座位,每个人可以匹配的座位是[1, li] || [ri, m],可能有人不需要匹配座位(默认满足),问最少有多少人不能被满足. 题解: 首先可以看出这是一 ...

  3. 洛谷 P2827 蚯蚓 解题报告

    P2827 蚯蚓 题目描述 本题中,我们将用符号 \(\lfloor c \rfloor\) 表示对 \(c\) 向下取整,例如:\(\lfloor 3.0 \rfloor = \lfloor 3.1 ...

  4. cookie中的path与domain属性详解

    1.domain表示的是cookie所在的域,默认为请求的地址,如网址为www.jb51.net/test/test.aspx,那么domain默认为www.jb51.net.而跨域访问,如域A为t1 ...

  5. Tile Cut~网络流入门题

    Description When Frodo, Sam, Merry, and Pippin are at the Green Dragon Inn drinking ale, they like t ...

  6. 几种list集合的区别

    SDK提供了有序集合接口java.util.List的几种实现,其中三种最为人们熟知的是Vector.ArrayList和LinkedList.有关这些List类的性能差别是一个经常被问及的问题.在这 ...

  7. bzoj 1064 图论

    我们根据能否看见建图,有向图边权设成1,然后我们转成无向图, 对于每条有向边连一条反边,边权是-1,然后从每个块中任意一个点开始 dfs,每个点有一个值,经过一条边到另一个点之后,用原来的点值和边权 ...

  8. jetty bleed漏洞利用工具

    两个exp: https://github.com/AppSecConsulting/Pentest-Tools/blob/master/jetty-bleed.py https://github.c ...

  9. Java相关框架

    框架 类型 设计(个人理解) HK2 自动注入框架 Jersey RESTful Jetty HTTP服务 Retrofit HTTP客户端 ActiveMQ 消息组件 主题.队列 Redis K-V ...

  10. java中 快捷键输入System.out.println();

    syso 然后:alt+ /(就是问号键)